The Device Context Attributes

As I noted above, Windows uses the device context to store ”attributes“ that govern how the GDI functions operate on the display. For instance, when you display some text using the TextOut function, you don't have to specify the color of the text or the font. Windows uses the device context to obtain this information.

When a program obtains a handle to a device context, Windows creates a device context with default values for all the attributes. The device context attributes are shown in the following table. A program can change or obtain any of the attributes.

Device Context Attribute Default Function(s) to Change Function(s) to Get

Mapping mode MM_TEXT SetMapMode GetMapMode
Window origin (0, 0) SetWindowOrg GetWindowOrg

OffsetWindowOrg

Viewport origin (0, 0) SetViewportOrg GetViewportOrg

OffsetViewportOrg

Window extents (1, 1) SetWindowExt GetWindowExt

SetMapMode

Viewport extents (1, 1) SetViewportExt GetViewportExt

SetMapMode

Pen BLACK_PE SelectObject SelectObject
Brush WHITE_BRUSH SelectObject SelectObject
Font SYSTEM_FONT SelectObject SelectObject
Bitmap None SelectObject SelectObject
Current pen position (0, 0) MoveTo

LineTo

GetCurrentPosition
Background mode OPAQUE SetBkMode GetBkMode
Background color White SetBkColor GetBkColor
Text color Black SetTextColor GetTextColor
Drawing mode R2_COPYPEN SetROP2 GetROP2
Stretching mode BLACKONWHITE SetPolyFillMode GetPolyFillMode
Polygon filling mode ALTERNATE SetPolyFillMode GetPolyFillMode
Intercharacter spacing 0 SetTextCharacterExtra GetTextCharacterExtra
Brush origin (0, 0) in screen coordinates SetBrushOrg GetBrushOrg
Clipping region None SelectObject SelectObject
    SelectClipRgn

IntersectClipRect

OffsetClipRgn

ExcludeClipRect

GetClipBox