A device context is actually a complicated web of structures and objects linked using pointers, spreading in both user mode application address space and kernel mode system address space.
A device context serves two important purposes within the graphics system. The main purpose is to provide an abstraction of a graphics device, such that anything above the device driver, which includes the graphics engine, the Win32 client DLLs, and the user application, can be device independent. Another usage of a device context is for storing commonly used drawing attributes, like foreground color, raster operation, pen, brush, font, etc., such that individual drawing calls do not have to carry these settings over and over again.
A device context is a structure that defines a set of graphic objects and their associated attributes, as well as the graphic modes that affect output. The graphic objects include a pen for line drawing, a brush for painting and filling, a bitmap for copying or scrolling parts of the screen, a palette for defining the set of available colors, a region for clipping and other operations, and a path for painting and drawing operations. The remainder of this section is divided into the following three areas.