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
  • 相关阅读:
    互联网人25岁毕业 拿一万块钱月薪 (转)
    在windows平台编译openAL Android 库
    lua简单包装
    libevent 简单学习
    cocos2dx中使用tolua++使lua调用c++函数
    《OpenGL超级宝典》编程环境配置
    快速排序、归并排序、堆排序三种算法性能比较
    二叉树的三种遍历的递归与非递归算法
    boost之bind
    boost之内存管理
  • 原文地址:https://www.cnblogs.com/findumars/p/6002333.html
Copyright © 2011-2022 走看看