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

Loading map documents into the PageLayoutControl and MapControl<br />

Individual data layers or preauthored ESRI map documents can be loaded into the<br />

MapControl and PageLayoutControl. You can either load the sample map document<br />

provided, or you can load your own map document. Later you will add an<br />

<strong>ArcGIS</strong> command to the ToolbarControl, which will allow you to browse to a map<br />

document.<br />

1. Programmatically add data to the PageLayoutControl. To do so you will write a<br />

new function, LoadData.<br />

a. Place a forward declaration after the forward declaration for the<br />

CloseAppCallback function at the top of MapViewer.h.<br />

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

XtPointer call_data);<br />

void LoadData();<br />

b. Now define LoadData in MapViewer.cpp after the definition for the<br />

CloseAppCallback function.<br />

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

XtPointer call_data)<br />

{<br />

…<br />

}<br />

Data can also be loaded to the toolbar’s buddy<br />

at runtime by using<br />

esriControlCommands.ControlsOpenDocCommand,<br />

a command that will be placed on the toolbar<br />

later in this scenario.<br />

void LoadData()<br />

{<br />

CComBSTR MX_DATAFILE;<br />

MX_DATAFILE =<br />

L"../data/arcgis_engine_developer_guide/gulf of st. lawrence.mxd";<br />

VARIANT_BOOL bValidDoc;<br />

g_ipPageLayoutControl->CheckMxFile(MX_DATAFILE, &bValidDoc);<br />

if (bValidDoc)<br />

g_ipPageLayoutControl->LoadMxFile(MX_DATAFILE);<br />

}<br />

c. Call LoadData from the main function after the widgets are placed in<br />

FormSetup.<br />

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

LoadData();<br />

2. You want the same map to appear in the MapControl. When the document in<br />

the PageLayoutControl changes, the contents of the MapControl must be<br />

updated. To do that, you must listen for events in the PageLayoutControl by<br />

writing a class that inherits from IPageLayoutControlEventsHelper. Open a new<br />

text file called PageLayoutControlEvents.h. Place the following code into that<br />

file, making sure to include the macro IUNKNOWN_METHOD_DEFS to<br />

implement IUnknown:<br />

#ifndef __PAGELAYOUTCONTROLEVENTS_H_<br />

#define __PAGELAYOUTCONTROLEVENTS_H_<br />

// ArcObjects Headers<br />

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

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

Saved successfully!

Ooh no, something went wrong!