# IPicture::get_CurDC

Returns the handle of the current device context. This property is valid only for bitmap pictures.

HRESULT get_CurDC(

HDC* phdcOut | //Receives a pointer to device context
); |

Parameters

phdcOut
  [out] Pointer to the caller’s variable to receive the device context.

Return Values

This method supports the standard return value E_FAIL, as well as the following:

S_OK
  The device context was returned successfully.
E_POINTER
  The address in phdcOut is not valid. For example, it may be NULL.

Remarks

The CurDC property and the IPicture::SelectPicture method exist to circumvent restrictions in Windows; specifically, that an object can only be selected into exactly one device context at a time. In some cases, a picture object may be permanently selected into a particular device context (for example, a control may use a certain picture for a background). To use this picture property elsewhere, it must be temporarily deselected from its old device context, selected into the new device context for the operation, then reselected back into the old device context. The IPicture::get_CurDC method returns the device context handle into which the picture is currently selected. The IPicture::SelectPicture method selects the picture into a new device context, returning the old device context and the picture’s GDI handle. The caller should select the picture back into the old device context when the caller is done with it, as is normal for Windows code.

#### Notes to Callers

The caller always owns any device contexts passed between it and the picture object. Since the picture object maintains a copy of the HDC, the caller should use a memory device context (created with the Win32 function CreateCompatibleDC) and not a screen device context (from GetDC, CreateDC, or BeginPaint), because the screen device contexts are a limited system resource.

See Also

IPicture::SelectPicture