[CPP]View PlainCopy
- /*
- Msdn:
- Any application this adds or removes fonts from the System font table should notify other windows of the change by sending A wm_fontchange message to all top-level windows in the operating system. The application should send this message by calling the SendMessage function and setting the HWND parameter to HWND_BROADC Ast.
- When an application no longer needs a font resource then it loaded by calling the AddFontResource function, it must remove That's resource by calling the RemoveFontResource function.
- This function installs the font is the current session. When the system restarts, the font is not being present. To has the font installed even after restarting the system, the font must is listed in the registry.
- */
- Defined as member variable
- CFont font;
- TCHAR Szpath[max_path];
- initialization function
- _tcscpy (szpath, _t ("%s"), _t ("F://11.ttf"));
- LOGFONT LF;
- Lf.lfheight = 60;
- Lf.lfwidth = 30;
- lf.lfescapement = 0;
- lf.lforientation = 0;
- Lf.lfweight = 90;
- lf.lfitalic = 0;
- Lf.lfunderline = 0;
- lf.lfstrikeout = 0;
- Lf.lfcharset = Default_charset;
- lf.lfoutprecision = 0;
- Lf.lfclipprecision = Clip_stroke_precis;
- lf.lfquality = 0;
- lf.lfpitchandfamily = 0;
- _tcscpy (Lf.lffacename, _t ("XXX")); //This is the font name
- Font. CreateFontIndirect (&LF);
- ASSERT (font. Getsafehandle ());
- You can then call the following code to set the font
- if (! AddFontResource (szpath))
- {
- AfxMessageBox (_t ("Load font failed."));
- return;
- }
- :: SendMessage (Hwnd_broadcast, wm_fontchange, 0, 0);
- GetDlgItem (IDOK)->setfont (&font);
- Release font resources When you don't need them at the end
- RemoveFontResource (szpath);
http://blog.csdn.net/visualeleven/article/details/6248115
The application loads the external font file (using the AddFontResource API function to specify the font)