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.

C++ APPLICATION PROGRAMMING INTERFACE<br />

3. Manage the widgets.<br />

4. Implement event listening and callback functions for widgets.<br />

5. Display the widgets.<br />

6. Begin the event handling loop.<br />

7. Shut down the application.<br />

To illustrate each of these steps, you will create a simple Motif application.<br />

Motif Program: Simple PushButton<br />

This application will be a single button that displays the number of times the<br />

button was clicked repeatedly to cerr (for example, if double-clicked it will<br />

display “2 clicks”). Start a new file that will be your program. Here that file will<br />

be called pbExample.cpp.<br />

To use the Motif Toolkit you will need to include the Motif header file. The<br />

Motif PushButton widget you will be using requires Xm/PushB.h (each widget’s<br />

header file includes Xm/Xm.h, but it is good practice to include it anyway). For<br />

the display of “pushed”, you will need to include iostream. Xm/Protocols.h will<br />

be used for the callbacks. You will also need a main function. Set these up in your<br />

new file, so that it looks like this:<br />

#include <br />

#include <br />

#include <br />

#include <br />

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

{<br />

return 0;<br />

}<br />

at the top of your new file.<br />

Step 1: Initialize the Motif Toolkit<br />

Your first initialization step is to set the language procedure for Xt. Do so by<br />

calling XtSetLanguageProc. Then you will initialize the Motif Toolkit with a call<br />

to XtVaAppInitialize. This call does a few things: connects the application to the<br />

display; gets any standard command-line arguments; sets up resources; and creates<br />

and returns the top-level window widget, which will be the parent of all other<br />

widgets in this applicaiton.<br />

A deeper understanding of these calls is not necessary to using Motif as it is used<br />

in samples. However, if you would like further information on the parameters<br />

passed into either function, see the Motif Programming Manual resource listed at<br />

the end of this topic.<br />

In <strong>ArcGIS</strong> <strong>Engine</strong> applications, you must use<br />

AoInitialize as well, placing the call before any<br />

ArcObjects usage.<br />

The code shown in gray has already been<br />

entered in previous steps. It is given here to<br />

illustrate the accurate placement of the code you<br />

are adding in this step.<br />

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

{<br />

XtSetLanguageProc(NULL, NULL, NULL);<br />

XtAppContext app_context;<br />

Widget topLevel = XtVaAppInitialize(&app_context, "XApplication",<br />

NULL, 0, &argc, argv, NULL, NULL);<br />

Chapter 4 • <strong>Developer</strong> environments • 235

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

Saved successfully!

Ooh no, something went wrong!