欢迎访问:常州市武进区嘉泽中心小学网站 !今天是:
栏目列表
您现在的位置是:首页>>教师>>计算机技术>>程序设计>>杂项>>文章内容
使用AddFontResource使用临时字体
发布时间:2008-11-20   点击:   来源:本站原创   录入者:佚名
 

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.

the code maybe such as:
 CString  sSourceDir  =  "D:\\TT6\\";  //temporary dir           
           //.TTF  file  name. 
           CString  sFontFileName  =  "TT6.TTF";  //temporary font file           
           //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"); 
           //Copying file is used to install font file 
           CopyFile((sSourceDir  +  sFontFileName),(sFontDir  +  sFontFileName),FALSE); 
           BOOL  Result; 
           Result  =  CreateScalableFontResource(0,  sFOTFile,  sFontFileName,  sFontDir); 
           Result  =  AddFontResource(sFOTFile); 

 //Write regedit for using this font file forever
           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));    

论坛对应的帖子:http://{域名已经过期}/Expert/topic/3955/3955083.xml?temp=.2840235


附件:
    关闭窗口
    打印文档
    账号登录
    保持登录 忘记密码?
    账号与武进教师培训平台同步