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