[1] example 1
BelowCodeIs placed in the oninitdialog of the dialog box class. Note that m_font is a class member function. Otherwise, the setfont may be faulty due to the failure of local variables.
Cfont * pfont = m_e2.getfont (); // cedit m_e2; <br/> assert (null! = Pfont); <br/> logfont lf; <br/> int nret = pfont-> getlogfont (& lf); <br/> assert (0! = Nret); <br/> lf. lfheight =-60; // set the height <br/> m_font.createfontindirect (& lf); // cfont m_font; is a class member function <br/> m_e2.setfont (& m_font );
[2] Example 2
In this example, only the font height is changed, and the font width remains unchanged.
Void cmy3455dlgdlg: onbutton1 () <br/>{</P> <p> cclientdc DC (this); <br/> logfont; <br/> cfont objfont; </P> <p> DC. getcurrentfont ()-> getlogfont (& logfont); <br/> logfont. lfheight * = 2; // double the font size <br/> // logfont. lfwidth = 0; // Note: If this sentence is added, the font width is changed based on the font height to maintain the font ratio. <Br/> logfont. lfquality = draft_quality; </P> <p> objfont. createfontindirect (& logfont); <br/> DC. selectObject (objfont); </P> <p> DC. textout (0, 0, text ("China"), 4); <br/>}