2.1.1 Accessing Output Devices

Any Windows application can use GDI functions to access an output device. GDI passes calls, which are device independent, from the application to the device driver. The device driver then translates the calls into device-dependent operations.

2.1.1.1 Saving and Restoring a Device Context

The SaveDC and RestoreDC functions save and restore device contexts. The former saves the original attributes, and the latter makes them available at a later time. For example, a Windows application may need to save its original clipping region so that it can restore the original state of the client area after a series of alterations occur.

2.1.1.2 Deleting a Device Context

The DeleteDC function deletes a device context and ensures that shared resources are not removed until the last context is deleted. The device driver is a shared resource. DeleteDC should be used to delete device contexts created by the application. If the application uses the GetDC function to retrieve a device context, it should use the ReleaseDC function, not DeleteDC.

2.1.1.3 Creating a Compatible Device Context

The CreateCompatibleDC function causes Windows to treat a portion of memory as a virtual device. Then Windows prepares a device context that has the same attributes as the device for which the virtual device was created, but the device context has no connected output device.

To use the compatible device context, the application creates a compatible bit-map and selects it into the device context. Any output the application sends to the device is drawn in the selected bitmap. Because the device context is compatible with an actual device, the context of the bitmap can be copied directly to the actual device, or vice versa. This also means that the application can send output to memory (prior to sending it to the device).

Note:

The CreateCompatibleDC function works only for devices that support raster operations. To discover whether a device supports raster operations, an application can call the GetDeviceCaps function with the RC_BITBLT index.

2.1.1.4 Creating an Information Context

The CreateIC function creates an information context for a device. An information context is a device context with limited capabilities; it cannot be used to write to the device. An application uses an information context to gather information about the selected device. Information contexts are useful in large applications that require memory conservation.

By using an information context and the GetDeviceCaps function, you can obtain the following device information:

Device technology

Physical display size

Color capabilities of the device

Color-palette capabilities of the device

Drawing objects available on the device

Clipping capabilities of the device

Raster capabilities of the device

Curve-drawing capabilities of the device

Line-drawing capabilities of the device

Polygon-drawing capabilities of the device

Text capabilities of the device