CDC,CPAINTDC,CCLIENTDC,CWINDOWDC differences

Source: Internet
Author: User

CDC,CPAINTDC,CCLIENTDC,CWINDOWDC differences

————————————————————————

1, first, the DC to explain:

Windows applications draw graphics on the "canvas" of the logical meaning of the DC representation by creating a device description table for the specified device (screen, printer, etc.). A DC is a data structure that contains device information that contains the various state information required by a physical device. The WIN32 program needs to get the DC handle hdc before drawing the graph and release it when it is not in use.

2. Then, straighten out the derived class relationship of CDC:

CObject Public |------CDC

Public |------|------CCLIENTDC

Public |------|------CPAINTDC

Public |------|------CWINDOWDC

Public |------|------CMETAFILEDC

(Note: Three derived classes other than CMetaFileDC are used for graphical drawing.)

3, the specific difference, in the following:

CDC is the base class for Windows drawing devices CClientDC:

(1) (Customer area device context) is used for the output of the client area, associated with a particular window, allowing the developer to access the client area in the target window, which contains the GETDC in its constructor, and the destructor contains the ReleaseDC

CPAINTDC:

(1) used to respond to a window redraw message (WM_PAINT) is the drawing output.

(2) 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.

(3) CPaintDC can only be used in WM_PAINT message processing.
CWINDOWDC:

(1) you can draw graphics in a non-client area, and CCLIENTDC,CPAINTDC can only draw graphics in the customer area.

(2) The coordinates origin is in the upper left corner of the screen, and the CCLIENTDC,CPAINTDC coordinates origin is in the upper left corner of the client area.

(3) Associate a specific window that allows the developer to draw on any part of the target window, including boundaries and headings, which are sent with the Wm_ncpaint message

Description: It is recommended to use CCLIENTDC,CPAINTDC and CWINDOWDC objects when drawing, rather than using CDC objects directly.

Example: CClientDC *PDC = new CClientDC (this); CWINDOWDC DC (this);

————————————————————————

Good Luck!

CDC,CPAINTDC,CCLIENTDC,CWINDOWDC differences

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.