IOleInPlaceSiteWindowless::GetDC

Provides an object with a handle to a device context for a screen or compatible device from its container.

HRESULT GetDC(
  LPCRECT pRect,   //Pointer to rectangle
  DWORD grfFlags,  //OLEDCFLAGS value
  HDC* phDC        //Pointer to device context
);
 

Parameters

pRect
[in] Pointer to the rectangle that the object wants to redraw, in client coordinates of the containing window. If this parameter is NULL, the object's full extent is redrawn.
grfFlags
[in] A combination of values from the OLEDCFLAGS enumeration.
phDC
[out] Pointer to a returned device context.

Return Values

S_OK
A device context was successfully returned.
OLE_E_NESTEDPAINT
The container is already in the middle of a paint session. That is, this method has already been called, and the ReleaseDC method has not yet been called.

Remarks

A device context obtained by this method should be released by calling IOleInPlaceSiteWindowless::ReleaseDC.

Like other methods in this interface, rectangles are specified in client coordinates of the containing window. The container is expected to intersect this rectangle with the object's site rectangle and clip out everything outside the resulting rectangle. This prevents objects from inadvertently drawing where they are not supposed to.

Containers are also expected to map the device context origin so the object can draw in client coordinates of the containing window, usually the container's window. If the container is merely passing its window device context, this occurs automatically. If it is returning another device context, for example, an offscreen memory device context, then the viewport origin should be set appropriately.

Notes to Implementers

Depending whether it is returning an on-screen or off-screen device context and depending on how sophisticated it is, container can use one of the following algorithms:

  1. On-screen, one pass drawing

    In the GetDC method, the container should:

    In the ReleaseDC method, the container should:

  2. On-screen, two pass drawing

    In the GetDC method, the container should:

    In the ReleaseDC method, the container should:

  3. Off-screen drawing

    In the GetDC method, the container should:

    In the ReleaseDC method, the container should:

When this method returns, the clipping region in the device context should be set so that the object can't paint in any area it is not supposed to. If the object is not opaque, the background should have been painted. If the device context is a screen, any overlapping opaque areas should be clipped out.

QuickInfo

  Windows NT: Use version 4.0 or later. New for OC96.
  Windows: Use Windows 95 or later. New for OC96.
  Windows CE: Unsupported.
  Header: Declared in ocidl.h.

See Also

IOleInPlaceSiteWindowless::ReleaseDC, OLEDCFLAGS