MFC displays device context Cclient DC (this) and CPaintDC DC (this)

Source: Internet
Author: User
Tags message queue

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.