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.

C++ APPLICATION PROGRAMMING INTERFACE<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 />

Step 1: Initialize GTK<br />

Initialize GTK with a call to gtk_init(&argc, &argv);. This call does a few things:<br />

sets up resources, initializes everything needed to work with GTK, and parses<br />

some command-line options.<br />

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

{<br />

gtk_init(&argc, &argv);<br />

}<br />

return 0;<br />

Step 2: Create the widgets<br />

With the toolkit initialized, you can create the single widget you are using in this<br />

application. First you will need to create the window in which you will place the<br />

button. Then you will create the button itself with gtk_button_new_with_label,<br />

since you want a labeled button in this example.<br />

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

{<br />

gtk_init(&argc, &argv);<br />

GtkWidget *window, *button;<br />

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);<br />

button = gtk_button_new_with_label("Push the button.");<br />

}<br />

return 0;<br />

Step 3: Place the widgets<br />

For the widgets to show up, they must be added to the main window as follows:<br />

button = gtk_button_new_with_label("Push the button.");<br />

gtk_container_add(GTK_CONTAINER(window), button);<br />

To use multiple widgets in an application, they must be packed. This is done with<br />

horizonal or vertical boxes or panes. Some of the calls related to packing include<br />

gtk_box_pack_start(), gtk_hbox_new(), gtk_vpaned_new(), and<br />

gtk_paned_add1(). Since this example only uses a single widget, this step is not<br />

needed. For additional information on it, see either the reference at the end or<br />

the samples.<br />

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

You now have a button, but for that to be useful you must hook it to some<br />

functionality. Widgets are attached to behavior at certain events through special<br />

callback functions. You can add callbacks to a widget after it is created.<br />

button = gtk_button_new_with_label("Push the button.");<br />

g_signal_connect(G_OBJECT(button), "button_press_event",<br />

G_CALLBACK(ClickCallback), NULL);<br />

These parameters have the following roles:<br />

• button—the widget that will give off the signal you are watching for.<br />

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