在win32 sdk中如何创建ttf字体

freshman45 2011-08-03 11:05:40
在win32中,如何创建一个自定义的ttf字体。
...全文
306 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
freshman45 2011-08-04
  • 打赏
  • 举报
回复
结贴,发现自己碰到了如下问题:

字符集跟字体不匹配,到最后都设置为default的,就木有问题。

还有对于

SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);

其实,如果你只是某个窗体需要使用该字体只要向该窗体发送这个消息,而并不需要对所有窗体发这个消息,这样子,速度很慢。
辰岡墨竹 2011-08-03
  • 打赏
  • 举报
回复
你得先把它复制到系统的字体文件夹里去。才能创建字体,用CreateFontIndirect就可以创建所用的字体了。
http://msdn.microsoft.com/en-us/library/94hsa63e(v=vs.71).aspx
freshman45 2011-08-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dizuo 的回复:]
自定义ttf啊?ttf是矢量字体,涉及曲线知识。
[/Quote]
[Quote=引用 4 楼 visualeleven 的回复:]
你要自己创建字体文件?http://kb.cnblogs.com/a/1722608/
看下这个,希望对你有帮助~
[/Quote]

不好意思是我没表述清楚,
比如我有一个 a.ttf文件,然后我就想通过这个ttf来创建字体
Eleven 2011-08-03
  • 打赏
  • 举报
回复
你要自己创建字体文件?http://kb.cnblogs.com/a/1722608/
看下这个,希望对你有帮助~
ryfdizuo 2011-08-03
  • 打赏
  • 举报
回复
自定义ttf啊?ttf是矢量字体,涉及曲线知识。
freshman45 2011-08-03
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fangchao918628 的回复:]
http://blog.sina.com.cn/s/blog_4b44e1c00100i9zc.html
这个.....
[/Quote]

我要创建的这个ttf文件,是外部的,而不是系统自带的。
fangchao918628 2011-08-03
  • 打赏
  • 举报
回复
freshman45 2011-08-03
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 bokutake 的回复:]
你得先把它复制到系统的字体文件夹里去。才能创建字体,用CreateFontIndirect就可以创建所用的字体了。
http://msdn.microsoft.com/en-us/library/94hsa63e(v=vs.71).aspx
[/Quote]

好像直接把字体文件放到系统的字体文件夹里面是不行的,还是需要调用接口注册的
freshman45 2011-08-03
  • 打赏
  • 举报
回复

/*
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);


可以这样子,但我还是不成功,挺奇怪的

19,466

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 图形处理/算法
社区管理员
  • 图形处理/算法社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧