发表于: 2005-04-21 13:38:26
注:1.该字体文件名与字体名称相同。 2.将字体放在windowsfonts目录下,我的程序启动后字体不能正常显示,需要点击运行字体文件才管用。 代码如下: AddFontResource("d:\myfont.ttf"); SendMessage(WND_BROADCAST,0,0); //应该是:SendMessage(HWM_FONTCHANGE, WND_BROADCAST,0,0); //但这样写,编译时会报错。 //是否先用CreateScalableFontResource()创建资源文件?该如何调用该函数? |
#1 得分:0回复于: 2005-04-21 13:46:46
应该是:SendMessage(HWND_BROADCAST,WM_FONTCHANGE, 0, 0);
|
|
#2 得分:0回复于: 2005-04-21 13:52:40
使用应该是这样的:
1.使用 AddFontResource 把您的字体送入 Windows 字体列表。 2.使用 SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0) 广播通知。 3.这时候开始,您的字体才可以随意使用。 4.使用 RemoveFontResource 从 Windows 字体列表删除您的字体。 5.SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0) 再通知一遍。 |
|
#3 得分:0回复于: 2005-04-21 13:56:14
如果是使用资源中的字体,应该:
To install unique hidden font resources follow these steps: 1、Copy the TrueType font file to a temporary file with a unique filename such as "ttfont01.ttf" that can be owned by the instance of the application. 2、Call the CreateScalableFontResource() function to create a uniquely named temporary hidden font resource file that can also be owned by the instance of the application. 3、Call the AddFontResource() function to install this uniquely named font resource file for this instance of the application. 4、Use the font in the application as desired. 5、When the instance of the application terminates or is otherwise finished with the font file, it should uninstall the font resource by calling the RemoveFontResource() function until it fails. 6、Lastly, the instance of the application should delete the temporary font resource file and the temporary TrueType font file that it created. |
|
#4 得分:0回复于: 2005-04-21 14:02:07
1.关于字体:
http://msdn.microsoft.com/library/en-us/gdi/fontext_371v.asp 2.安装和删除字体 http://msdn.microsoft.com/library/en-us/gdi/fontext_2ylq.asp |
|
#5 得分:0回复于: 2005-04-21 14:19:57
CreateScalableFontResource 为一种TureType字体创建一个资源文件,以便能用API函数AddFontResource将其加入Windows系统 !
|
|
|
#6 得分:0回复于: 2005-04-21 14:49:04
SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
不好意思!上面这个函数没有用错,是我在这里写错的。 vcleaner提的文章我看过了,我英语不好,只识得文章中的绝大部分单词,文意看的似懂非懂。 现在还是茅塞未开,多谢vcleaner! 能有相关代码就好了! |
#7 得分:0回复于: 2005-04-21 14:56:25
如果可以的话,你将你的程序源代码发给我,我看看能不能改好!
xia_qingqi@broadxent.com.cn |
|
#8 得分:100回复于: 2005-04-21 16:05:16
//应该是:SendMessage(HWM_FONTCHANGE, WND_BROADCAST,0,0);
//但这样写,编译时会报错。 ============================= 使用全局API函数: ::SendMessage(HWND_BROADCAST,WM_FONTCHANGE, 0, 0); 编译就不会出错了! |
|
#9 得分:0回复于: 2005-05-09 10:44:31
永久安装使用,类似下面的代码:
CString sSourceDir = "D:\TT6\"; //.TTF file name. CString sFontFileName = "TT6.TTF"; //Font description (as it will appear in Control Panel). CString sFontName = "金梅粗圓體(TrueType)"; TCHAR sWinDir [MAX_PATH]; GetWindowsDirectory(sWinDir,MAX_PATH); CString sFontDir(sWinDir); sFontDir += "\Fonts\"; CString sFOTFile = sFontDir; sFOTFile += (sFontFileName.Left(sFontFileName.GetLength()-4) + ".FOT"); CopyFile((sSourceDir + sFontFileName),(sFontDir + sFontFileName),FALSE); BOOL Result; Result = CreateScalableFontResource(0, sFOTFile, sFontFileName, sFontDir); Result = AddFontResource(sFOTFile); HKEY phkResult; DWORD RegResult; LONG Rlt = RegCreateKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts", 0, "REG_SZ", 0, KEY_WRITE, 0,&phkResult ,&RegResult); if(Rlt != ERROR_SUCCESS) { AfxMessageBox("Create Key Failed!"); } RegSetValueEx(phkResult, sFontName, 0, REG_SZ, (CONST BYTE* )((LPCTSTR)sFontFileName), sFontFileName.GetLength()); RegCloseKey(phkResult); ::SendMessage (HWND_BROADCAST, WM_FONTCHANGE, 0, 0); DeleteFile((sFontDir + sFontFileName)); |