MSDN上有这几个函数的解释和例子: 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 "Arial")); // lpszFacename// Do something with the font just created... CClientDC dc(this); CFont* def_font = dc.SelectObject(&font); dc.TextOut(5, 5, "Hello", 5); dc.SelectObject(def_font);// Done with the font. Delete the font object. font.DeleteObject();CClientDC dc(this);CFont font; VERIFY(font.CreatePointFont(120, "Arial", &dc));// Do something with the font just created... CFont* def_font = dc.SelectObject(&font); dc.TextOut(5, 5, "Hello", 5); dc.SelectObject(def_font);// Done with the font. Delete the font object. font.DeleteObject();CFont font; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); // zero out structure lf.lfHeight = 12; // request a 12-pixel-height font strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial" VERIFY(font.CreateFontIndirect(&lf)); // create the font// Do something with the font just created... CClientDC dc(this); CFont* def_font = dc.SelectObject(&font); dc.TextOut(5, 5, "Hello", 5); dc.SelectObject(def_font);// Done with the font. Delete the font object. font.DeleteObject();
// Initializes a CFont object with the characteristics given // in a LOGFONT structure. CFont font; LOGFONT lf; memset(&lf, 0, sizeof(LOGFONT)); // zero out structure lf.lfHeight = 12; // request a 12-pixel-height font strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial" VERIFY(font.CreateFontIndirect(&lf)); // create the font// Do something with the font just created... CClientDC dc(this); CFont* def_font = dc.SelectObject(&font); dc.TextOut(5, 5, "Hello", 5); dc.SelectObject(def_font);// Done with the font. Delete the font object. font.DeleteObject(); 一样的, CreateFontIndirect只不过是把那些参数封装到一个LOGFONT结构里去了而已.
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
"Arial")); // lpszFacename// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);// Done with the font. Delete the font object.
font.DeleteObject();CClientDC dc(this);CFont font;
VERIFY(font.CreatePointFont(120, "Arial", &dc));// Do something with the font just created...
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);// Done with the font. Delete the font object.
font.DeleteObject();CFont font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // zero out structure
lf.lfHeight = 12; // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial"
VERIFY(font.CreateFontIndirect(&lf)); // create the font// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);// Done with the font. Delete the font object.
font.DeleteObject();
// in a LOGFONT structure.
CFont font;
LOGFONT lf;
memset(&lf, 0, sizeof(LOGFONT)); // zero out structure
lf.lfHeight = 12; // request a 12-pixel-height font
strcpy(lf.lfFaceName, "Arial"); // request a face name "Arial"
VERIFY(font.CreateFontIndirect(&lf)); // create the font// Do something with the font just created...
CClientDC dc(this);
CFont* def_font = dc.SelectObject(&font);
dc.TextOut(5, 5, "Hello", 5);
dc.SelectObject(def_font);// Done with the font. Delete the font object.
font.DeleteObject();
一样的, CreateFontIndirect只不过是把那些参数封装到一个LOGFONT结构里去了而已.