CreateCompatibleDC

The CreateCompatibleDC function creates a memory device context (DC) compatible with the specified device.

HDC CreateCompatibleDC(
  HDC hdc   // handle to the device context
);
 

Parameters

hdc
Handle to an existing device context. If this handle is NULL, the function creates a memory device context compatible with the application's current screen.

Return Values

If the function succeeds, the return value is the handle to a memory device context.

If the function fails, the return value is NULL.

Windows NT: To get extended error information, call GetLastError.

Remarks

A memory device context is a device context that exists only in memory. When the memory device context is created, its display surface is exactly one monochrome pixel wide and one monochrome pixel high. Before an application can use a memory device context for drawing operations, it must select a bitmap of the correct width and height into the device context. This may be done by using CreateCompatibleBitmap specifying the height, width, and color organization required in the function call.

When a memory device context is created, all attributes are set to normal default values. The memory device context can be use as a normal device context. You can set the attributes to non-default values, obtain the current setting of its attributes, select pens, brushes and regions into it.

The CreateCompatibleDC function can only be used with devices that support raster operations. An application can determine whether a device supports these operations by calling the GetDeviceCaps function.

When you no longer need the memory device context, call the DeleteDC function to delete it.

ICM: If the device context (DC) that is passed to this function through its hdc parameter is enabled for Independent Color Management (ICM), the DC created by the function is ICM-enabled. The source and destination color spaces are specified in the DC. 

QuickInfo

  Windows NT: Requires version 3.1 or later.
  Windows: Requires Windows 95 or later.
  Windows CE: Requires version 1.0 or later.
  Header: Declared in wingdi.h.
  Import Library: Use gdi32.lib.

See Also

Device Contexts Overview, Device Context Functions, CreateCompatibleBitmap, DeleteDC, GetDeviceCaps