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 />

b. Place the implementation for this class into CustomizeDialogEvents.cpp,<br />

making sure you include the header file for the class. Implement the functions<br />

so that when the dialog box is opened, the toolbar enters the customize<br />

state, and when it is closed, the toolbar leaves that state. When it is<br />

closed, also make sure to set the toggle button to false, as the dialog box<br />

may be closed with a close button that is on it.<br />

#include "CustomizeDialogEvents.h"<br />

HRESULT CustomizeDialogEvents::OnStartDialog()<br />

{<br />

g_ipToolbarControl->put_Customize(VARIANT_TRUE);<br />

return S_OK;<br />

}<br />

HRESULT CustomizeDialogEvents::OnCloseDialog()<br />

{<br />

g_ipToolbarControl->put_Customize(VARIANT_FALSE);<br />

XmToggleButtonSetState(g_customizeToggle, false, true);<br />

Although the class itself is Motif or GTK specific,<br />

listening for either one is done the same way.<br />

return S_OK;<br />

}<br />

c. Like the other event classes, these events must be listened for. Start by<br />

including the header file in MapViewer.h.<br />

#include "MapControlEvents.h"<br />

#include "CustomizeDialogEvents.h"<br />

#include "AddDate.h"<br />

d. Declare variables for those events at the top of MapViewer.cpp.<br />

IEventListenerHelperPtr g_ipMapControlEvent2Helper;<br />

CustomizeDialogEvents* g_customizeEvents;<br />

IEventListenerHelperPtr g_ipCustomizeEventHelper;<br />

e. Listen for them right after listening for MapControl events.<br />

g_ipMapControlEvent2Helper->AdviseEvents(ipMapControl, NULL);<br />

g_customizeEvents = new CustomizeDialogEvents();<br />

g_ipCustomizeEventHelper.CreateInstance(CLSID_CustomizeDialogEventsListener);<br />

g_ipCustomizeEventHelper->Startup(<br />

static_cast (g_customizeEvents));<br />

CComBSTR bsGUID;<br />

::StringFromIID(IID_ICustomizeDialogEvents, &bsGUID);<br />

IUIDPtr ipUID(CLSID_UID);<br />

ipUID->put_Value(CComVariant(bsGUID));<br />

g_ipCustomizeEventHelper->AdviseEvents(g_ipCustomizeDialog, ipUID);<br />

f. Clean up the events in CloseAppCallback.<br />

// End event listening<br />

g_ipPageLayoutControlEventHelper->UnadviseEvents();<br />

g_ipPageLayoutControlEventHelper->Shutdown();<br />

406 • <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!