18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

BUILDING APPLICATIONS WITH C++ AND CONTROL WIDGETS<br />

// Load the same pre-authored map document into the MapControl<br />

CComBSTR DocFileName;<br />

IPageLayoutControl2Ptr ipPage2 = g_ipPageLayoutControl;<br />

ipPage2->get_DocumentFilename(&DocFileName);<br />

g_ipMapControl->LoadMxFile(DocFileName);<br />

}<br />

6. Since events have been added, you need to tell the main application to listen<br />

for them. Do this by creating an instance of the new class in the main function<br />

of MapViewer.cpp and by using the IEventListenerHelper interface.<br />

a. First, include PageLayoutControlEvents.h at the top of MapViewer.h.<br />

#include <br />

// Events<br />

#include "PageLayoutControlEvents.h"<br />

b. In MapViewer.cpp, declare the global variables to use in listening for events.<br />

IPageLayoutControlPtr g_ipPageLayoutControl;<br />

// Events<br />

PageLayoutControlEvents* g_pageLayoutEvents;<br />

IEventListenerHelperPtr g_ipPageLayoutControlEventHelper;<br />

c. Place the code to begin listening after the FormSetup in main, and before the<br />

data is loaded.<br />

FormSetup(argc, argv, &app_context);<br />

In GTK, the event cleanup will be done in<br />

delete_event, a callback used with<br />

destroy_event to close the application.<br />

// Event listening<br />

g_pageLayoutEvents = new PageLayoutControlEvents();<br />

g_ipPageLayoutControlEventHelper.CreateInstance(<br />

CLSID_PageLayoutControlEventsListener);<br />

g_ipPageLayoutControlEventHelper->Startup(<br />

static_cast(g_pageLayoutEvents));<br />

g_ipPageLayoutControlEventHelper->AdviseEvents(g_ipPageLayoutControl,<br />

NULL);<br />

7. Before closing the application, you must clean up the events by calling<br />

UnadviseEvents and Shutdown, as well as deleting the instance of<br />

PageLayoutControlEvents. This is done in CloseAppCallback before the control<br />

interface pointers are set to 0.<br />

// Function called when WM_DELETE_WINDOW protocol is passed<br />

void CloseAppCallback(Widget w, XtPointer client_data, XtPointer call_data)<br />

{<br />

// End event listening<br />

g_ipPageLayoutControlEventHelper->UnadviseEvents();<br />

g_ipPageLayoutControlEventHelper->Shutdown();<br />

g_ipPageLayoutControlEventHelper = 0;<br />

delete g_pageLayoutEvents;<br />

g_ipToolbarControl = 0;<br />

Chapter 6 • <strong>Developer</strong> scenarios • 373

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!