Skip to main content

Device Context

  • 2 minutes to read

One of the chief features of the Microsoft® Win32® application programming interface (API) is device independence. Win32-based applications can draw and print output on a variety of devices. The software supporting this device independence is contained in two dynamic-link libraries. The first, GDI32.DLL, is referred to as the graphics device interface (GDI); the second is referred to as a device driver. The name of the second depends on the device where an application draws output. For example, if an application draws output in the client area of its window on a VGA display, this library is VGA.DLL; if it prints output on an Epson® FX-80 printer, this library is EPSON9.DLL.

An application must inform GDI of loading a particular device driver and, once the driver is loaded, to prepare a device for drawing operations (such as selecting the line color and width, the brush pattern and color, the font typeface and clipping region, etc.) This can be accomplished by creating and maintaining a device context. The device context is a structure that defines a set of graphic objects and their associated attributes, and the graphic modes affecting output. Graphic objects include:

  • A pen for line drawing;

  • A brush for painting and filling;

  • A bitmap for copying or scrolling screen sections;

  • A palette for defining a set of available colors;

  • A region for clipping and other operations;

  • A path for painting and drawing operations.

Unlike most of the Win32 structures, applications do not have direct access to the device context; instead, they operate indirectly by calling various functions.