Use this subroutine to draw a Polygon on the screen. With this example, the polygon will not persist on the screen; it will disappear when the screen next refreshes. See the Buffer Polygons sample for an example showing how drawings can be persisted on the display.
How to use
- Stub out the code to implement a tool.
- Paste the code below into its OnMouseDown event.
- Add the tool to an ArcMap toolbar, select it, and click somewhere on the focus map.
STDMETHODIMP CToolControl1::OnMouseDown(LONG button, LONG shift, LONG x, LONG y)
{
IDocumentPtr ipDoc;
m_ipApp->get_Document(&ipDoc);
IMxDocumentPtr ipMxDoc(ipDoc);
IMapPtr ipMap;
ipMxDoc->get_FocusMap(&ipMap);
IActiveViewPtr ipActiveView(ipMap);
IScreenDisplayPtr ipScreenDisplay;
ipActiveView->get_ScreenDisplay(&ipScreenDisplay);
IRubberBandPtr ipRubberPolygon(CLSID_RubberPolygon);
IRgbColorPtr ipRgbColor(CLSID_RgbColor);
ipRgbColor->put_Red(255);
ISimpleFillSymbolPtr ipFillSymbol(CLSID_SimpleFillSymbol);
ipFillSymbol->put_Color(ipRgbColor);
ISymbolPtr ipSym(ipFillSymbol);
IGeometryPtr ipGeometry;
ipRubberPolygon->TrackNew(ipScreenDisplay, ipSym, &ipGeometry);
OLE_HANDLE hDC;
ipScreenDisplay->get_hDC(&hDC);
ipScreenDisplay->StartDrawing(hDC, esriNoScreenCache);
ipScreenDisplay->SetSymbol(ipSym);
ipScreenDisplay->DrawPolygon(ipGeometry);
ipScreenDisplay->FinishDrawing();
return S_OK;
}
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced |