Locate coordinates in a MapControl
LocateCoordinates.cpp
// Copyright 2010 ESRI
// 
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
// 
// You may freely redistribute and use this sample code, with or
// without modification, provided you include the original copyright
// notice and use restrictions.
// 
// See the use restrictions.
// 


#include <stdio.h>
#include <QtGui/QtGui>
#include <ArcSDK.h>
#include <olb/esridefensesolutions.h>

#include <Ao/AoControls.h>
#include <AxCtl/qtaxctl.h>
#include "MapControlEvents.h"

#if defined(ESRI_UNIX)
    void DsInitialize();
#endif

void add_toolbar_items(IToolbarControl* pToolbar);
IToolbarControlPtr ipToolbar;
IMapControl3Ptr    ipMap;
ITOCControlPtr     ipToc;
MapControlEvents* mapEvents;
IEventListenerHelperPtr ipMapControlEvent2Helper;

int main(int argc, char **argv)
{

    // Initialize the Engine
    ::AoInitialize(NULL);

    //Initialize Defense Solutions
#if defined(ESRI_UNIX)
    DsInitialize();
#endif
    {
        IAoInitializePtr ipInit(CLSID_AoInitialize);
        esriLicenseStatus status;
        ipInit->Initialize(esriLicenseProductCodeEngine, &status);
        if (status != esriLicenseCheckedOut)
        {
            printf("Invalid Licensing.\n");
            AoExit(0);
        }
    }


  QApplication qapp(argc, argv);

    //add toolbar and splitter to a vertical box
    QWidget vbox;
    QVBoxLayout layout;
    QAxCtl tlb(AoPROGID_ToolbarControl, NULL, "Toolbar Control");
    QSplitter split(NULL);
    layout.addWidget(&tlb);
    layout.addWidget(&split);
        //input widgets
    QWidget hbox;
    QGridLayout gridLayout;
    QLabel xLabel("X");
    QLabel yLabel("Y");
    QLabel dmsLabel("DMS");
    QLabel utmLabel("UTM");
    QLabel mgrsLabel("MGRS");
    QLineEdit xText;
        QLineEdit yText;
        QLineEdit dmsText;
        QLineEdit utmText;
        QLineEdit mgrsText;
    xText.setObjectName("XObj");
    yText.setObjectName("YObj");
    dmsText.setObjectName("DMSObj");
    utmText.setObjectName("UTMObj");
    mgrsText.setObjectName("MGRSObj");
    //make Edit boxes readonly
    xText.setReadOnly(true);
    yText.setReadOnly(true);
    dmsText.setReadOnly(true);
    utmText.setReadOnly(true);
    mgrsText.setReadOnly(true);

    //add input widgets to a grid layout
    gridLayout.addWidget(&xLabel, 0, 0);
    gridLayout.addWidget(&xText, 0, 1, 1, 4);
    gridLayout.addWidget(&yLabel, 1, 0);
    gridLayout.addWidget(&yText, 1, 1, 1, 4);
    gridLayout.addWidget(&dmsLabel, 2, 0);
    gridLayout.addWidget(&dmsText, 2, 1, 1, 4);
    gridLayout.addWidget(&utmLabel, 3, 0);
    gridLayout.addWidget(&utmText, 3, 1, 1, 4);
    gridLayout.addWidget(&mgrsLabel, 4, 0);
    gridLayout.addWidget(&mgrsText, 4, 1, 1, 4);
    hbox.setLayout(&gridLayout);
        layout.addWidget(&hbox);
    vbox.setLayout(&layout);

    tlb.setMinimumHeight(30);
    tlb.setMaximumHeight(30);
    split.setMinimumHeight(400);
    split.setMinimumWidth(500);

    QAxCtl toc(AoPROGID_TOCControl, &split, "TOC Control");
    QAxCtl map(AoPROGID_MapControl, &split, "Map Control");
    toc.setMaximumWidth(100);

    vbox.show();
        {

        HRESULT hr;
        hr = tlb.getInterface((IUnknown **)&ipToolbar);
        hr = toc.getInterface((IUnknown **)&ipToc);
        hr = map.getInterface((IUnknown **)&ipMap);

        if (ipToolbar != 0)
            ipToolbar->SetBuddyControl(ipMap);
        if (ipToc != 0)
            ipToc->SetBuddyControl(ipMap);

        add_toolbar_items(ipToolbar);

        mapEvents = new MapControlEvents();
        ipMapControlEvent2Helper.CreateInstance(CLSID_MapControlEvents2Listener);
        ipMapControlEvent2Helper->Startup(static_cast<IMapControlEvents2Helper*> (mapEvents));
        ipMapControlEvent2Helper->AdviseEvents(ipMap, NULL);

    }

    qapp.exec();

    // Uninitialize the engine
    {
        IAoInitializePtr ipInit(CLSID_AoInitialize);
        ipInit->Shutdown();
    }
    ::AoUninitialize();

    AoExit(0);
    return 0;
}

void add_toolbar_items(IToolbarControl* pToolbar)
{
    CComVariant varTool;
    long itemindex;

    if (!pToolbar)
        return;

    varTool = L"esriControlCommands.ControlsOpenDocCommand";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);

    varTool = L"esriControlCommands.ControlsMapZoomInTool";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_TRUE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapZoomOutTool";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapZoomInFixedCommand";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapZoomOutFixedCommand";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapPanTool";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapFullExtentCommand";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapZoomToLastExtentBackCommand";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsMapZoomToLastExtentForwardCommand";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsSelectFeaturesTool";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
    varTool = L"esriControlCommands.ControlsSelectTool";
    pToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
        esriCommandStyleIconOnly, &itemindex);
}