THE DEVICE CONTEXT

When you want to draw on a graphics output device (such as the screen or a printer), you must first obtain a handle to a device context (or DC). In giving your program this handle, Windows is giving you permission to use the device. You then include the handle as a parameter in the GDI functions to identify to Windows the device you want to draw on.

The device context contains many current ”attributes“ that determine how the GDI functions work on the device. These attributes allow the parameters to the GDI functions to include only starting coordinates or sizes and not everything else that Windows needs to display the object on the device. For example, when you call TextOut, you need specify in the function only the device context handle, the starting coordinates, the text, and the length of the text. You don't need to specify the font, the color of the text, the color of the background behind the text, and the intercharacter spacing, because these attributes are part of the device context. When you want to change one of these attributes, you call a function that changes the attribute in the device context. Subsequent TextOut calls use the changed attribute.