18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

Although it might look like a new instance of<br />

AoInitialize is created, it is a singleton object, so<br />

this returns a pointer to the same AoInitialize<br />

object created before.<br />

// Start the application running<br />

XtRealizeWidget(topLevel);<br />

}<br />

9. In the previous step you set up a callback to listen for window manager protocols<br />

to close on command. Now implement the callback for when the application<br />

is closed.<br />

a. First give a forward declaration of the function. This is placed right after<br />

the declaration for XtResizeWidget at the top of MapViewer.h.<br />

extern "C" void XtResizeWidget(Widget, _XtDimension,<br />

_XtDimension, _XtDimension);<br />

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

XtPointer call_data);<br />

b. Write the function in MapViewer.cpp after FormSetup. Shut down and<br />

uninitialize the <strong>ArcGIS</strong> <strong>Engine</strong> <strong>Developer</strong> Kit, then exit.<br />

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

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

XtPointer call_data)<br />

{<br />

// Uninitialize the engine<br />

{<br />

IAoInitializePtr ipInit(CLSID_AoInitialize);<br />

ipInit->Shutdown();<br />

}<br />

::AoUninitialize();<br />

AoExit(0);<br />

}<br />

10. A final <strong>ArcGIS</strong> <strong>Engine</strong> C++ API call is required to turn the application over<br />

to the X Toolkit Intrinsics, which handles passing events to the widgets. After<br />

this call, the application code sits idle and waits for user-generated events.<br />

This will end your main function.<br />

int main(int argc, char* argv[])<br />

{<br />

…<br />

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

The GTK equivalent is gtk_main.<br />

// Start the application running<br />

XtAppMainLoop(app_context);<br />

}<br />

11. Compile the application by typing “make –f Makefile.SolarisMotif ” at the<br />

command line.<br />

12. Run the application by typing either “make –f Makefile.SolarisMotif run” or<br />

“./MapViewer” at the command line. You will see an empty form titled<br />

MapViewer.<br />

364 • <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!