MapTocToolbar.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 <ArcSDK.h> // The following must be undefined to prevent redefining C++ method names. // Redefine them later, appending __ESRI_WRAPPER, if access to the // corresponding Win32 API call is required. #undef GetCursor #undef SetCursor #undef GetScrollRange #undef GetScrollPos #undef SetScrollPos #undef GetCapture #undef GetTopWindow #undef ScrollWindow #include <AxCtl/wxaxctl.h> #include <Ao/AoControls.h> class RootFrame: public wxFrame { public: RootFrame(const wxString& title, const wxPoint& pos, const wxSize& size); void SetBuddies(); void AddToolbarItems(); private: wxAxCtl *map, *tlb, *toc; IMapControl4Ptr ipMapCtl; IToolbarControlPtr ipTlbCtl; ITOCControlPtr ipTocCtl; }; class MapTocToolbarApp: public wxApp { bool OnInit(); int OnRun(); int OnExit(); RootFrame *frame; }; IMPLEMENT_APP(MapTocToolbarApp) bool MapTocToolbarApp::OnInit() { ::AoInitialize(NULL); { IAoInitializePtr ipInit(CLSID_AoInitialize); esriLicenseStatus status; ipInit->Initialize(esriLicenseProductCodeEngine, &status); if (status != esriLicenseCheckedOut) { fprintf(stderr, "Invalid Licensing (Engine).\n"); AoExit(0); } } frame = new RootFrame(_T("Test-TOC-Toolbar"), wxDefaultPosition, wxSize(600,500) ); frame->Show(TRUE); SetTopWindow(frame); return TRUE; } int MapTocToolbarApp::OnRun() { frame->SetBuddies(); frame->AddToolbarItems(); return wxApp::OnRun(); } int MapTocToolbarApp::OnExit() { { IAoInitializePtr ipInit(CLSID_AoInitialize); ipInit->Shutdown(); } ::AoUninitialize(); return wxApp::OnExit(); } RootFrame::RootFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, -1, title, pos, size) { wxPanel *panel = new wxPanel(this, wxID_ANY); wxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL); wxBoxSizer *hbox = new wxBoxSizer(wxHORIZONTAL); tlb = new wxAxCtl(panel, wxID_ANY, AoPROGID_ToolbarControl, wxDefaultPosition, wxSize(-1,28)); map = new wxAxCtl(panel, wxID_ANY, AoPROGID_MapControl , wxDefaultPosition, wxDefaultSize); toc = new wxAxCtl(panel, wxID_ANY, AoPROGID_TOCControl , wxDefaultPosition, wxSize(200,-1)); vbox->Add(tlb, 0, wxEXPAND); vbox->Add(hbox, 1, wxEXPAND); hbox->Add(toc, 0, wxEXPAND); hbox->Add(map, 1, wxEXPAND); panel->SetSizer(vbox); } void RootFrame::SetBuddies() { HRESULT hr; hr = map->GetInterface((IUnknown **)&ipMapCtl); if(!SUCCEEDED(hr)) return; hr = tlb->GetInterface((IUnknown **)&ipTlbCtl); if(!SUCCEEDED(hr)) return; hr = toc->GetInterface((IUnknown **)&ipTocCtl); if(!SUCCEEDED(hr)) return; ipTlbCtl->SetBuddyControl(ipMapCtl); ipTocCtl->SetBuddyControl(ipMapCtl); } void RootFrame::AddToolbarItems() { CComVariant varTool; long itemindex; if (ipTlbCtl == 0) return; varTool = L"esriControlCommands.ControlsOpenDocCommand"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapZoomInTool"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_TRUE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapZoomOutTool"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapZoomInFixedCommand"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapZoomOutFixedCommand"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapPanTool"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapFullExtentCommand"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapZoomToLastExtentBackCommand"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsMapZoomToLastExtentForwardCommand"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsSelectFeaturesTool"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); varTool = L"esriControlCommands.ControlsSelectTool"; ipTlbCtl->AddItem(varTool, 0, -1, VARIANT_FALSE, 0, esriCommandStyleIconOnly, &itemindex); }