Tip-set the font for cedit
Keywords: Cedit font logfont cfont
Set the font for ceditCode:
Within. H of the class
Cmyedit * m_pedit;
Cfont font;
In the CPP file of the class:
Logfont lf;
Memset (& lf, 0, sizeof (logfont ));
Lf. lfheight = height; // request a 12-pixel-height font
// Lf. lfwidth = 0;
Lf. lfweight = fw_bold;
Strcpy (LF. lffacename, "Arial"); // request a face name "Arial"
Verify (font. createfontindirect (& lf); // create the font
M_pedit = new cmyedit;
M_pedit-> Create (ws_child | ws_visible | ws_tabstop, crect (1, 1, width + 1, height + 1), this, 100 );
M_pedit-> setfont (& font );
Note that:
The cedit: setfont () function is required to set the font of the cedit control. However, the input parameter cannot be a local variable and must be valid throughout the entire survival period of the cedit control, therefore, you need to set the cfont variable to an in-class parameter or global. In short, cfont must exist when cedit exists.