应用程序加载外部字体文件(使用AddFontResource API函数指定字体)
2016-10-26 23:22
295 查看
[cpp] view plain copy
/*
MSDN:
Any application that 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_BROADCAST.
When an application no longer needs a font resource that it loaded by calling the AddFontResource function, it must remove that resource by calling the RemoveFontResource function.
This function installs the font only for the current session. When the system restarts, the font will not be present. To have the font installed even after restarting the system, the font must be listed in the registry.
*/
// 定义为成员变量
CFont font;
TCHAR szPath[MAX_PATH];
// 初始化函数
_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")); // 这里就是字体名
font.CreateFontIndirect(&lf);
ASSERT(font.GetSafeHandle());
// 之后就可以调用下面的代码来设置字体了
if(!AddFontResource(szPath))
{
AfxMessageBox(_T("Load font failed."));
return ;
}
::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);
GetDlgItem(IDOK)->SetFont(&font);
// 最后不需要的时候释放字体资源
RemoveFontResource(szPath);
http://blog.csdn.net/visualeleven/article/details/6248115
相关文章推荐
- 应用程序加载外部字体文件
- 加载asset中的文件字体以及使用
- flash as3,使用 URLLoader 加载外部文件
- Silverlight实用窍门系列:2.Silverlight动态加载外部XML指定地址的WebService---(动态加载外部XML文件中指定的WebService地址)【附带实例源码】
- 2.Silverlight动态加载外部XML指定地址的WebService-(动态加载外部XML文件中指定的WebService地址)
- 使用javascript动态加载外部css或js文件
- wince下应用程序使用外部字体实现多国语言
- JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
- JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
- JS对外部文件的加载及对IFRMAME的加载的实现,当加载完成后,指定指向方法(方法回调)
- Silverlight实用窍门系列:2.Silverlight动态加载外部XML指定地址的WebService---(动态加载外部XML文件中指定的WebService地址)
- C#使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- C#使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- C#使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- 使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- 使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- 使用线程加载指定目录下的所有子目录和文件名称到TreeView中
- flash as3使用,播放声音和加载外部声音文件
- 重新想象 Windows 8 Store Apps (33) - 关联启动: 使用外部程序打开一个文件或uri, 关联指定的文件类型或协议
- android中图片加载使用LruCache缓存到内存或外部文件的功能