zoukankan      html  css  js  c++  java
  • 应用程序加载外部字体文件(使用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
  • 相关阅读:
    浅谈 cosos2d-x 的ImageView和Sprite的区别
    浅谈JS数据遍历的几种方式
    浅谈Cocos2d-js cc.director
    JavaScript的Let用法
    JS开发工具WebStorm使用快捷键
    python 文件操作
    浅谈代码自动构建工具
    rhel6.4 zabbix 安装时少的bcmath mbstring
    Security:090476]Invalid/unknown SSL header was received from peer locahost during SSL handshake
    jconsole
  • 原文地址:https://www.cnblogs.com/findumars/p/6002333.html
Copyright © 2011-2022 走看看