1 CPaintDC class
(1) The CPaintDC class is a derived class of the CDC class that is typically used in a function onpaint () that responds to WM_PAINT messages.
(2) The WM_PAINT message is a window message that fires when an area of a window needs to be redrawn. The message handler function OnPaint () is automatically called when a message in the program loops to the WM_PAINT message, and if an object of the CPaintDC class is defined within the OnPaint function, the class object can be used to complete the drawing operation in the view client area using the member functions of the CDC class. (3) CPaintDC is used for drawing output when the response window redraws the message (WM_PAINT). CPaintDC calls BeginPaint () in the constructor to get the device context, and in the destructor, call EndPaint () to release the device context. EndPaint () is responsible for purging the WM_PAINT message from the message queue in addition to freeing the device context. Therefore, when processing a window redraw, you must use CPAINTDC, otherwise the WM_PAINT message cannot be purged from the message queue, causing a continuous window redraw. CPaintDC can only be used in WM_PAINT message processing.
2 CClientDC class
the CClientDC class is also a derived class of the CDC class. It can only be plotted in the client area of the window (that is, in the window except for the border, the title bar, the menu bar, and the middle part of the status bar), the coordinate point (0,0) usually refers to the upper-left corner of the customer area. Its constructor calls the GEGDC function, and the destructor calls the ReleaseDC function. The CCLIENTDC (Customer area device context) is used for the output of the client area, which encapsulates the GetDC () in the constructor and encapsulates the ReleaseDC () function in the destructor. This is typically used in response to a non-window redraw message (such as drawing text when keyboard input, mouse drawing). Usage is: CCLIENTDC DC (this);//this generally points to this window or the current active view DC. TextOut (10,10,str,str. GetLength ());//use DC output text, if used in CScrollView, also pay attention to calling OnPrepareDC (&DC) to adjust the coordinates of the device context.
MFC displays device context Cclient DC (this) and CPaintDC DC (this)