• 应用程序加载外部字体文件(使用AddFontResource API函数指定字体)



    [cpp]
     view plain copy
     
    1. /* 
    2. MSDN: 
    3.  
    4.   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.  
    5.  
    6.   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.  
    7.  
    8.   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. 
    9. */  
    10. // 定义为成员变量  
    11. CFont font;  
    12. TCHAR szPath[MAX_PATH];  
    13.   
    14. // 初始化函数  
    15. _tcscpy(szPath, _T("%s"), _T("F://11.ttf"));  
    16. LOGFONT lf;  
    17. lf.lfHeight = 60;  
    18. lf.lfWidth = 30;  
    19. lf.lfEscapement = 0;  
    20. lf.lfOrientation = 0;  
    21. lf.lfWeight = 90;   
    22. lf.lfItalic = 0;   
    23. lf.lfUnderline = 0;  
    24. lf.lfStrikeOut = 0;   
    25. lf.lfCharSet = DEFAULT_CHARSET;   
    26. lf.lfOutPrecision = 0;   
    27. lf.lfClipPrecision = CLIP_STROKE_PRECIS;  
    28. lf.lfQuality = 0;  
    29. lf.lfPitchAndFamily = 0;   
    30. _tcscpy(lf.lfFaceName, _T("XXX")); // 这里就是字体名   
    31. font.CreateFontIndirect(&lf);  
    32. ASSERT(font.GetSafeHandle());  
    33.   
    34. // 之后就可以调用下面的代码来设置字体了  
    35. if(!AddFontResource(szPath))  
    36. {  
    37.   AfxMessageBox(_T("Load font failed."));  
    38.   return ;  
    39. }  
    40. ::SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0);  
    41. GetDlgItem(IDOK)->SetFont(&font);  
    42.   
    43. // 最后不需要的时候释放字体资源  
    44. RemoveFontResource(szPath);  
     
     http://blog.csdn.net/visualeleven/article/details/6248115
  • 相关阅读:
    Linux内核等待队列机制介绍
    对数学的思考
    Linux 进程状态
    linux内核链表
    linux内核的经典书籍
    似乎最近发的Blog又少了
    抽象——放弃细节的另外一个说法
    成长
    发现QQ的一个小问题
    放上了一篇几个月前写的东西
  • 原文地址:https://www.cnblogs.com/findumars/p/6002333.html
Copyright © 2020-2023  润新知