// The code fragment shows how to create a font object, // select the font object into a DC (device context) for text // drawing, and finally delete the font object.// Initializes a CFont object with the specified characteristics. CFont font; VERIFY(font.CreateFont( 12, // nHeight 0, // nWidth 0, // nEscapement 0, // nOrientation FW_NORMAL, // nWeight FALSE, // bItalic FALSE, // bUnderline 0, // cStrikeOut ANSI_CHARSET, // nCharSet OUT_DEFAULT_PRECIS, // nOutPrecision CLIP_DEFAULT_PRECIS, // nClipPrecision DEFAULT_QUALITY, // nQuality DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily _T("Arial"))); // lpszFacename// Do something with the font just created... CClientDC dc(this); CFont* def_font = dc.SelectObject(&font); dc.TextOut(5, 5, _T("Hello"), 5); dc.SelectObject(def_font);// Done with the font. Delete the font object. font.DeleteObject();
// The code fragment shows how to create a font object,
// select the font object into a DC (device context) for text
// drawing, and finally delete the font object.// Initializes a CFont object with the specified characteristics.
CFont font;
VERIFY(font.CreateFont(
12, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
_T("Arial"))); // lpszFacename// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, _T("Hello"), 5);
dc.SelectObject(def_font);// Done with the font. Delete the font object.
font.DeleteObject();
不过最好还是养成用完就释放的习惯
CFont *Font1;
CFont *Font2;
LOGFONT lf;
Font1 =new CFont;
Font2 =new CFont;
Font1->CreatePointFont(200,L"华文隶书");
Font2->CreatePointFont(200,L"华文隶书");
Font1->GetLogFont(&lf);
Font2->GetLogFont(&lf);
Font1->DeleteObject();
Font2->DeleteObject();
Font1->CreateFontIndirect(&lf);
Font2->CreateFontIndirect(&lf);
m_StaticName.SetFont(Font1,true);
m_StaticWish.SetFont(Font2,true);
Font1,改不了字体,可以改大小,Font2就什么都能改.为什么