VC CDC, HDC, PDC differences and contacts and mutual conversion _c language

Source: Internet
Author: User
Tags textout

What is the difference between 1.CDC *PDC and HDC hdc , similar to CWnd *pwnd and HWND?

The PDC is a class pointer
HDC is a Windows handle
Obtain HDC through the PDC:
HDC Hdc=pdc->getsafehdc ();
To obtain the PDC through HDC:
CDC *pdc=new CDC;
Pdc->attach (HDC);

2.hDC is fundamentally different from the CDC.

HDC is a data type of windows and is a device description handle. The CDC is a class in MFC that encapsulates almost all the operations on HDC. It can be said that the HDC-defined variable points to a piece of memory that describes the relevant content of a device, so it is also possible to think that HDC defines a pointer, and the CDC class defines an object that has a HDC defined Device description table and also functions that are associated with HDC operations. This is the same as the difference between Hpen and Cpen,point and CPoint.

The CDC encapsulates HDC-related operations, such as a CDC textout function that implicitly detects errors that can be simplified to such a degree cdc:textout (int x, int y, const cstring& str)
{
TextOut (m_hDC, X, Y, (LPCTSTR) str, str. GetLength ());
}

M_HDC is the CDC's member variable HDC M_HDC;
CDC has a operator HDC () const {return M_HDC;}
You can use it as a hdc.

3.this is the pointer of DC output target window, it can get window handle and object with parameter construction. What's so strange about that?

CPAINTDC Invalid zone DC, equivalent to BeginPaint, EndPaint
CCLIENTDC client area DC, equivalent to GetDC, ReleaseDC
CWINDOWDC Full window DC, equivalent to GETWINDOWDC, ReleaseDC
CDC any DC, equivalent to CreateDC, DeleteDC

Iv. Differences and linkages

HDC is a handle; The CDC is a class related to MFC's encapsulated Windows devices; CClientDC is the CDC derived class that produces objects corresponding to the Windows client area
HDC is a data type of windows and is a device description handle.
The CDC is a class in MFC that encapsulates almost all the operations on HDC.
It can also be said that the variable defined by HDC points to a piece of memory, this memory is used to describe the relevant content of a device, so it is also possible to assume that HDC defines a pointer, and the CDC class defines an object that has a HDC definition of a Device description table and also a function that contains operations related to HDC.
This is the same as the difference between Hpen and Cpen,point and CPoint.

V. Access to CDC *

cdc* PDC
PDC=GETDC ();

Vi. acquisition of 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)

VII. Conversion

cdc* PDC
HDC HDC;
Pdc=attach (HDC);
HDC=GETSAFEHDC (PDC);
Pdc->m_hdc==hdc

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.