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

HRESULT AddDateTool::get_Cursor(OLE_HANDLE* cursorName)<br />

{<br />

if (cursorName == NULL)<br />

return E_POINTER;<br />

if (m_hCursor != 0)<br />

{<br />

*cursorName = m_hCursor;<br />

return S_OK;<br />

}<br />

return E_FAIL;<br />

}<br />

// Add the date to the page layout where the mouse is<br />

HRESULT AddDateTool::OnMouseDown(LONG Button, LONG Shift, LONG X, LONG Y)<br />

{<br />

if (Button == 1)<br />

{<br />

// Format the date & create a text element<br />

char* dateDisplay = FormatDate();<br />

ITextElementPtr ipDateTextElem(CLSID_TextElement);<br />

ipDateTextElem->put_Text(CComBSTR(dateDisplay));<br />

delete[] dateDisplay;<br />

ITextSymbolPtr ipDateTextSymb(CLSID_TextSymbol);<br />

// Add it to the text element<br />

ipDateTextElem->put_Symbol(ipDateTextSymb);<br />

// Get point in map display coordinates<br />

IActiveViewPtr ipActiveView;<br />

m_ipHookHelper->get_ActiveView(&ipActiveView);<br />

IScreenDisplayPtr ipScreenDisplay;<br />

ipActiveView->get_ScreenDisplay(&ipScreenDisplay);<br />

IDisplayTransformationPtr ipDisplayTrans;<br />

ipScreenDisplay->get_DisplayTransformation(&ipDisplayTrans);<br />

IPointPtr ipPoint;<br />

ipDisplayTrans->ToMapPoint(X, Y, &ipPoint);<br />

// Set the element's geometry<br />

((IElementPtr) ipDateTextElem)->put_Geometry(ipPoint);<br />

// Add element to the page layout's graphics container<br />

IGraphicsContainerPtr ipGraphicsContainer;<br />

ipActiveView->get_GraphicsContainer(&ipGraphicsContainer);<br />

ipGraphicsContainer->AddElement((IElementPtr) ipDateTextElem, 0);<br />

ipActiveView->PartialRefresh(esriViewGraphics, NULL, NULL);<br />

}<br />

return S_OK;<br />

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