This document is archived and information here might be outdated.  Recommended version.


IDisplay.StartDrawing Method (ArcObjects .NET 10.8 SDK)
ArcObjects Help for .NET developers > ArcObjects Help for .NET developers > ArcObjects namespaces > Display > ESRI.ArcGIS.Display > Interfaces > ID > IDisplay Interface > IDisplay.StartDrawing Method
ArcGIS Developer Help

IDisplay.StartDrawing Method

Prepare the display for drawing. Specify the device context and the cache to draw to (normally esriNoScreenCache). The ScreenDisplay coclass will automatically create a window device context if you specify hdc = 0.

[Visual Basic .NET]
Public Sub StartDrawing ( _
    ByVal hDC As Integer, _
    ByVal cacheID As Short _
)
[C#]
public void StartDrawing (
    int hDC,
    short cacheID
);
[C++]
HRESULT StartDrawing(
  OLE_HANDLE hDC,
  short cacheID
);
[C++]
Parameters
hDC [in]

hDC is a parameter of type OLE_HANDLE cacheID [in]
cacheID is a parameter of type short

Product Availability

Available with ArcGIS Engine, ArcGIS Desktop, and ArcGIS Server.

Remarks

StartDrawing and FinishDrawing are used to manage clipping, symbols, and caching. Call StartDrawing and FinishDrawing anytime you want to draw to a device such as a display, printer, or cache (bitmap).  However, if you are drawing in response to IActiveViewEvents::AfterDraw, the Map object automatically makes these calls for you.

StartDrawing has two parameters: hDc and cacheID.  The hDc parameter specifies the target device where drawing will occur, usually a display, printer, or bitmap.  The cacheID parameter activates a specific cache. In most cases, esriNoScreenCache should be used. 

Specifying a cache sets it as the screen's active cache.  When esriNoScreenCache is used, it sets the display's active cache to zero and drawing occurs directly in the device. Specify a cache when you don't want to draw to a screen directly and you instead want to draw to a cache (bitmap) that may ultimately be copied to the screen.  For example, when ArcMap draws geography, it draws it to a specific cache and then the cache is copied to the screen.  When the screen repaints, instead of drawing all the data from scratch again, the software checks if the cache is dirty or not and simply redraws the bitmap to save time if it can.  When drawing to a cache, the hDc parameter should be the device context of the bitmap, use the IScreenDisplay::CacheMemDC property to get a particular cache's hDC.

Each time you need to change the cache you are drawing to, you must do so inside a new StartDrawing / FinishDrawing block.  For example,  ArcMap usually creates three caches: one for geography layers, one for graphics and annotation, and one for selections.  ArcMap draws each of these phases within a separate StartDrawing / FinishDrawing block.

There are times when may need to draw shapes directly to screen without having them become part of a display cache.  For example, drawing moving objects.   In these cases, use IScreenDisplay::WindowDC to get the device context of the display and esriNoScreenCache as the cacheID.

If a zero is specified for the hDc parameter, the Windows API function GetDC is used to populate IScreenDisplay::WindowDC with the hDC of the main display and drawing is sent here.

As mentioned above, if you drawing in response to the IActiveView::AfterDraw event, the Map object calls StartDrawing and StopDrawing for you.  Also, if the draw phase you are drawing after is cached, your drawings will be cached as well.
StartDrawing fires the IDisplayEvents::DisplayStarted event.
[C++]
The following C++ code gives you an example drawing sequence.
VARIANT_BOOL isCacheDirty;
m_ipScreen->IsCacheDirty(esriScreenRecording, &isCacheDirty);

if (isCacheDirty) // draw from scratch
{
  m_ipScreen->StartRecording();
  m_ipScreen->StartDrawing((OLE_HANDLE)hPaintDC, esriNoScreenCache);
  DrawContents();
  m_ipScreen->FinishDrawing();
  m_ipScreen->StopRecording();
}
  else // draw from offscreen bitmap
{
  m_ipScreen->DrawCache((OLE_HANDLE)hPaintDC, esriScreenRecording, 0, 0);
}

See Also

IDisplay Interface | IDisplay.FinishDrawing Method