What is the relationship between cfont, logfont, and hfont? What is the difference between CDC * PDC and HDC?

Source: Internet
Author: User
Tags textout

Cfont ftfolders;
Cfont ftitems;
Cfont fthotitems;
Logfont lf;

Hfont HF = (hfont) getstockobject (default_gui_font );
Cfont * gf = cfont: fromhandle (HF );
GF-> getlogfont (& lf );
Lf. lfunderline = true;
Fthotitems. createfontindirect (& lf );
Lf. lfunderline = false;
Ftitems. createfontindirect (& lf );
Lf. lfweight = fw_semibold;
Ftfolders. createfontindirect (& lf );
Lf. lfheight = 20;
Ftcaption. createfontindirect (& lf );
**************************************
Logfont: A structure used to display a font in the logical table. For example, logfont. lffacename indicates the font name.
Hfont: a handle, equivalent to a font object in the memory, which can be used immediately
Cfont: an encapsulation of hfont by MFC

It can be said that logfont is a kind of ink name, such as the hero card, relatively abstract
Hfont indicates a real bottle of ink. You can use it when you open the bottle cap.
Cfont only adds a bottle of ink to a piece of paper. In fact, it is still a bottle of ink.

**************************************
When you need a simple font, you can use cfont.
If you need to define small details of fonts and other complex fonts, use logfont
Hfont can be a connection between the two of them.

**************************************
Cfont: How to Use getlogfont (logfont * logfont?
Cfont * pfont = new cfont;
Logfont;
Pfont-> getlogfont (& logfont );
Why not?

Patrickgamp is correct, at least as follows:
Cfont * pfont = new cfont;
Pfont-> createfont (... // many parameters are entered :(
Logfont;
Pfont-> getlogfont (& logfont) // get the stuff you just entered in create

Logfont;
Lstrcpy (lpstr) logfont. lffacename, (lpstr) "_ gb2312 ");
Logfont. lfweight = 700;
Logfont. lfwidth = 20;
Logfont. lfheight = 50;
Logfont. lfescapement = 0;
Logfont. lfunderline = false;
Logfont. lfitalic = false;
Logfont. lfstrikeout = false;
Logfont. lfcharset = gb2312_charset; // It seems that none of the above parameters can be missing.

Pfont-> createfontindirect (& logfont );
// Now there is content. You can use it.
You can use cwnd: getfont to obtain the font of the current window.

**************************************** *****************
1. What is the difference between CDC * PDC and HDC? similar to cwnd * pwnd and hwnd?
PDC is a class pointer
HDC is a Windows handle
Use PDC to obtain HDC:
Hdchdc = PDC-> getsafehdc ();
Obtain PDC through HDC:
CDC * PDC = newcdc;
PDC-> attach (HDC );
2. essential differences between HDC and CDC
HDC is a data type in windows and a device description handle.
CDC is a class in MFC, which encapsulates almost all
HDC operation.
You can also say that the HDC variable points to a piece of memory.
Memory is used to describe the content of a device.
HDC defines a pointer, while the CDC class defines an object,
This object has a device description table defined by HDC, and also contains
Functions that contain HDC-related operations.
This is the same as Hpen, cpen, and point.
.
CDC encapsulates HDC-related operations. For example, a textout function of CDC hides its error detection, which can be simplified to this degree.
CDC: textout (intx, inty, constcstring & Str)
{
Textout (m_hdc, X, Y, (lpctstr) STR, str. getlength ());
}

M_hdc is the member variable hdcm_hdc of CDC;
CDC has an operatorhdc () const {returnm_hdc ;}
You can use it as an HDC
3. This is the pointer of the DC output target window. It can be used to obtain the window handle. What's strange about constructing an object with parameters?

Invalid cpaintdc zone DC, equivalent to beginpaint, endpaint
Cclientdc customer zone DC, equivalent to getdc, releasedc
Cwindowdc is equivalent to getwindowdc and releasedc.
CDC any DC, equivalent to createdc, deletedc

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.