CreateCompatibleDC

Syntax

HDC CreateCompatibleDC(hDC)

This function creates a memory device context that is compatible with the device specified by the hDC parameter. A memory device context is a block of memory that represents a display surface. It can be used to prepare images in memory before copying them to the actual device surface of the compatible device.

When a memory device context is created, GDI automatically selects a 1-by-1 monochrome stock bitmap for it.

Parameter Type/Description  

hDC HDC Identifies the device context. If hDC is NULL, the function creates a memory device context that is compatible with the system display.  

Return Value

The return value identifies the new memory device context if the function is successful. Otherwise, it is NULL.

Comments

This function can only be used to create compatible device contexts for devices that support raster operations. For more information, see the RC_BITBLT raster capability in the GetDeviceCaps function, later in this chapter.

GDI output functions can be used with a memory device context only if a bitmap has been created and selected into that context.

When the application no longer requires the device context, it should free it by calling the DeleteDC function.