在win32中,如何创建一个自定义的ttf字体。
解决方案 »
- 关于CRecordset的用法??
- 有没有办法在MFC的dialog中把excel表加进去,向excel一样实现操作。
- 如何用CryptoAPI实现RSA非对称加解密?
- 一个关于鼠标的很简单,但问了N个人却没人会的问题。
- 请热心朋友一看!
- 为何在win32 console程序中不能输出汉字?各位高手请帮忙出谋划策
- 有关tracert一问
- CScrollView 怎么溪钩啊?
- 谁能告诉我哪里能找到 libbzip2 压缩算法的源代码?
- 请问如何在程序里应用shdocvw.dll的接口和事件
- 炫彩界面库系列教程之360杀毒软件界面,XML实现,快速开发,c++,DirectUI
- 如何实现类似PAINT中毛笔画刷的干墨水效果和笔画边缘有毛刺效果
这个.....
我要创建的这个ttf文件,是外部的,而不是系统自带的。
看下这个,希望对你有帮助~
不好意思是我没表述清楚,
比如我有一个 a.ttf文件,然后我就想通过这个ttf来创建字体
http://msdn.microsoft.com/en-us/library/94hsa63e(v=vs.71).aspx
/*
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);
可以这样子,但我还是不成功,挺奇怪的