In VC CDC HDC and pDC are distinguished connected and converted
- 2020-05-05 11:38:49
- OfStack
What is the difference between CDC *pDC and HDC hdc ?
pDC is the class pointer
HDC is the windows handle
Get hdc:
from pDC
HDC hdc=pDC-
>
GetSafeHdc();
Get pDC:
through hdc
CDC *pDC=new CDC;
pDC-
>
Attach(hdc);
2. There are essential differences between hDC and CDC
HDC is a data type of WINDOWS and is a device description handle. CDC is a class in MFC that encapsulates almost all operations on HDC. It can also be said that the variable defined by HDC points to a block of memory, which is used to describe the contents of a device, so it can also be considered that HDC defines a pointer; The CDC class defines an object that has a device description table defined by HDC and also contains functions for operations related to HDC. This is the same difference between HPEN and CPen, POINT and CPoint.
CDC encapsulates the relevant operations of hDC. For example, an TextOut function of CDC hides its error detection, which can be completely simplified to the extent of CDC:TextOut(int x, int y, const CString& str)
m_hDC is the member variable of CDC HDC m_hDC;
3.this is the pointer to the output target window of dc, through which the window handle can be obtained.
CPaintDC dc
CClientDC dc, GetDC, ReleaseDC ReleaseDC
iv. Distinction and connection
HDC is a handle; CDC is a class related to Windows devices encapsulated by MFC. CClientDC is a derived class of CDC that produces
5. Obtain CDC *
{
TextOut( m_hDC, x, y, (LPCTSTR)str, str.GetLength() );
}
CDC has an operator HDC() const {return m_hDC; }
You can think of it as an HDC using
CWindowDC
windows any dc, is equivalent to CreateDC, DeleteDC
objects corresponding to Windows client areas
HDC is a data type of WINDOWS and is a device description handle.
CDC is a class in MFC that encapsulates almost all HDC operations.
It can also be said that the variable defined by HDC points to a block of memory, which is used to describe the contents of a device, so it can also be said that thinks that HDC defines a pointer; The CDC class defines an object, , which has a device description table defined by HDC, and also contains functions for operations related to HDC.
This is the same difference between HPEN and CPen, and POINT and CPoint.
CDC* pDC
pDC=GetDC();
6. Obtain hdc
HDC hDC;
1,hDC=GetDC(pCxp-
>
hWnd);
2,pDC-
>
m_hDC;
3,
MEMDCXP Mdcxp;
GetMemDCXP(&Mdcxp);
hDC = Mdcxp.hMemDC;
4,hDC=::GetDC(HWND handle)
7. Convert
CDC* pDC
HDC hDC;
pDC=Attach(hDC);
hDC=GetSafeHDC(pDC);
pDC-
>
m_hDC==hDC