The device context can be thought of as a toolbox, equipped with pens and brushes, as well as a canvas on which we can draw lines, paint figures, and write text. It also contains methods for converting between device and logical units. Finally, it can be regarded as a connection between our program and the screen or printer.
In Windows, a window usually has a frame with an icon at the top left corner, buttons to resize the window at the top right corner and, possibly a menu bar, a toolbar, and a status bar. the white area inside the frame is called the client area. With the help of a device context, we can paint the client area.
When the view class is created with the Application Wizard, the method OnDraw
is included. It takes a parameter pCD
that is a pointer to a device context. The device context class CDC
is a very central part of a Windows application. However, CDC
is an abstract class, a device context object is instantiated from the subclass ClientDC
. In order to...