The Device description table is a layout body containing information about the device (physical devices such as monitors, printers), and MFC has to do with the operation of the image in a DC.
HDC is a data type of windows and is a device description handle;
CDC is a class of MFC encapsulated Windows devices that are coherent;
CClientDC is a derived class of CDC that produces objects corresponding to the Windows client area, calls GetDC at the time of the institution, and invokes ReleaseDC at the time of the destructor;
CWINDOWDC is also the CDC's derivative class, call GETWINDOWDC at the time of the institution, call ReleaseDC in the destruction, can receive all of CWnd's screen, including customers and non-client areas.
The CDC is the base class for Windows Paint devices.
CCLIENTDC:
(Customer area equipment high and low text) for the output of the customer area, with a specific window engagement relationship, you can let the pioneer to meet the target window client area, its function contains GetDC, the destructor contains the ReleaseDC
CPAINTDC:
(1) Only onpaint processing penalty is used to respond to paint output when the window redraws the message (wm_paint). CPaintDC call BeginPaint () in the function of the organ to obtain the device high and low text, in the destructor call EndPaint () release device high and low text. EndPaint () is responsible for purging the WM_PAINT message from the message queue in addition to the high and low text of the device. Yes, CPAINTDC must be applied when processing penalty window redraw, otherwise WM_PAINT messages cannot be purged from message queue, causing the window redraw to continue. CPaintDC can only be used in the WM_PAINT message processing penalty.
(2) CPaintDC call BeginPaint () in the function of the organ to obtain the device high and low text, in the destructor call EndPaint () release device high and low text. EndPaint () is responsible for purging the WM_PAINT message from the message queue in addition to the high and low text of the device. Yes, CPAINTDC must be applied when processing penalty window redraw, otherwise WM_PAINT messages cannot be purged from message queue, causing the window redraw to continue.
(3) CPaintDC can only be used in the WM_PAINT message processing penalty.
CWINDOWDC:
(1) Drawings can be drawn in the 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) Contact a specific window, allow the creator in the target window of any project group to draw, including the gap and the topic, this DC with wm_ncpaint message all the way to send
Disclaimer: It is recommended to apply the CCLIENTDC,CPAINTDC and CWINDOWDC objects while drawing, rather than applying the CDC object directly, CWINDOWDC's organ function call GETWINDOWDC get the window DC (including the non-client area), The destructor calls ReleaseDC when it is necessary to manipulate the window's non-client area.
To draw a line for example, the above several DC application code is as follows:
HDC hdc;
HDC =:: GetDC (M_hwnd);
Movetoex (Hdc,m_ptorigin.x,m_ptorigin.y,null);
LineTo (HDC,POINT.X,POINT.Y);
:: ReleaseDC (M_HWND,HDC);
CDC * PDC = GetDC ();
Pdc->moveto (M_ptorigin);
Pdc->lineto (point);
ReleaseDC (PDC);
CCLIENTDC DC (this);
CCLIENTDC DC (GetParent ());
dc. MoveTo (M_ptorigin);
dc. LineTo (point);
CWINDOWDC DC (this); This represents only painting in the View area
CWINDOWDC DC (GetParent ());//painting in all frame areas
CWINDOWDC DC (GetDesktopWindow ());//Can be painted in all desktop areas
dc. MoveTo (M_ptorigin);
dc. LineTo (point);
HDC is the most primitive DC handle, and the first parameter of many APIs is an HDC type, such as
HDC HDC =:: GetDC (M_hwnd);
:: Movetoex (HDC, 0,0, NULL);
:: LineTo (HDC, 0, 100,);
:: ReleaseDC (M_hwnd, HDC);
In MFC, in order to encapsulate the API as a class to manipulate, it is more than a CDC. So in MFC, it's all
CDC DC = GetDC ();
dc. MoveTo (0,0);
dc. LineTo (0,100);
This->releasedc (&DC);
But this is not enough, because the CDC also want you to release, all MFC more out of a cclientdc, so you can do this:
CCLIENTDC DC (this);
dc. MoveTo (0,0);
dc. LineTo (0,100);
The destructor of the CCLIENTDC itself will acquit itself.
The DC is not what object, is the device high and low text abbreviation.
As with CClientDC, there are cwindowdc,cpaintdc, but their drawing limitations are not the same.
But to the end, are just some of the HDC package, you can directly reference M_HDC in the CDC class, this is the original HDC handle-
HDC, CDC, CClientDC, CWINDOWDC, CPaintDC
HDC is the handle of the DC, the CDC is a encapsulated DC class, the following three DC is the application of the situation slightly different, are derived from the CDC, the first is the client area DC, often used, the second is the window DC, for all windows to draw, CPaintDC as if only in the OnPaint function to apply it
The CDC is an MFC encapsulation of HDC, and CDC and HDC can be converted to each other:
HDC hdc = PDC->GETSAFEHDC (); PDC is cdc*, HDC obtained by CDC
cdc* PDC = Cdc::fromhandle (hdc);//Get CDC from HDC
FromHandle:
Static cdc* PASCAL FromHandle (hdc hdc);
return value:
A hands-on pointer for immediate application.
Note:
Returns a pointer to the CDC object when given a pointer to a device's high and low text. If the CDC object is not connected to a handle, a CDC object is created and connected to it. (see if the window that the handle refers to exists.) The window pointer is returned if it exists.)
CCLIENTDC, CWINDOWDC these two as far as possible, they for Ws_clipchildren attribute is ignored.
CPAINTDC is the most used in MFC, in fact cdc* is often the object of CPaintDC.
Ws_clipchildren
Brother: Do not care about those xxdc, just remember how to use HDC on it, all DC class, the bottom is in the toss hdc, as you directly learn to play HDC. Don't talk to the birds. DC, those DC, can be extracted from the HDC, put forward like the CDC
*PDC, Refining hdc:pdc->m_hdc; get the HDC itself to use the API to draw what?
The CDC class and its subclasses---cclientdc, CWINDOWDC, and CPaintDC
CDC class
Windows applies a device-independent graphics device scene (DC:D evice Context) for display. The MFC root base Class library defines the device scene object class----the CDC class.
Parent class: Straight from CObject. Continues the various characteristics of the CObject class, such as dynamic creation and so on.
For example, use GDI to draw a rectangle to Rectangle (HDC, ...). ), and the CDC is Dc.rectangle (...). ), the CDC master if the Dibon needs hdc as a parameter of the GDI function encapsulated, HDC became a member of its variable.
CPaintDC CWINDOWDC CClientDC: They are all persisted from the CDC, respectively, to the above-mentioned BEGINPAINT,GETWINDOWDC, GetDC call to encapsulate (CPaintDC organ when called BeginPaint, Destructors call EndPaint, the rest of the same).
There are only two data members:
HDC M_HDC:CDC Object application output device high and low text
HDC M_HATTRIBDC:CDC Object Applied property device high and low text
CClientDC sub-class
CClientDC class can only draw in customer area;
The so-called customer area refers to the window area to remove the border, title bar, menu bar, object bar, status bar, and other items in the group, it is the user can manipulate the area;
When applying cclientdc for drawing, it is generally necessary to call the GetClientRect () function to obtain the size of the client area;
The CClientDC class calls the Windows API function GetDC () in an organ function, and responds to ReleaseDC () at the time of the destructor;
The window handle of the CClientDC class is stored in the member variable m_hwnd, CCLIENTDC for the institution, and CWnd is passed as a parameter to the organ function.
CWINDOWDC sub-class
The CWINDOWDC object calls the Windows API function GETWINDOWDC at the time of the destructor, ReleaseDC the API function that invokes the response at the time of destruction, which means that the CWINDOWDC object can receive a full-screen area that the CWnd points to;
CWINDOWDC allowed to draw on the display's casual position. The coordinate origin is in the upper-left corner of the entire window.
When applying CWINDOWDC for drawing, it is generally necessary to call the GetWindowRect function to get the size of the entire application window area;
The window handle of the CWINDOWDC class is stored in the member variable m_hwnd, CCLIENTDC for the institution, and CWnd is passed as a parameter to the organ function.
CPaintDC sub-class
Usually CPAINTDC is used to respond to WM_PAINT messages. Generally applied in the OnPaint function.
CClientDC is also derived from the CDC. The GETDC function is invoked actively when the organization is called, and the RELEASEDC function is called actively when the destructor is refactored. Generally applied to the drawing of the client Area window.
CPaintDC can only be applied in WM_PAINT messages for memory device images that are applied when a redraw message is emitted, while CCLIENTDC and client areas are coherent, and there is a memory device image that is applied when the redraw message is issued, and can be applied anywhere.
When handling penalty window redraw, you must apply CPAINTDC, otherwise WM_PAINT messages cannot be purged from the message queue and will cause the window redraw to continue.
What is GDI? GDI is a graphical programming library supplied by Microsoft.
What is a DC? DC is a concept defined in the GDI library. It doesn't make any sense to be obsessed with what a DC is, because Microsoft does not expose its implementation to the DC.
HDC is a hgdiobj. Just like Audi is a kind of car.
To create a transparent paint brush:
CBrush *pbrush=cbrush::
FromHandle ((Hbrush) Getstockobject (Null_brush));
Function Prototypes:
Hgdiobj getstockobject (int fnobject);
Reprinted from: http://www.xuebuyuan.com/1774574.html
Individual subclasses of DC, CDC, and CDC