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
  • 相关阅读:
    最全QQ空间说说伪装代码
    Office文件找回技巧
    CentOS7安装CMake(arm版)华为云服务器
    centos7修改ssh端口
    CentOS7安装zookeeper(ARM)版——华为服务器
    CentOS7安装JDK1.8
    Centos7安装Docker
    Prometheus+mysqld_exporter
    Prometheus+blackbox_exporter
    Prometheus+node_exporter
  • 原文地址:https://www.cnblogs.com/findumars/p/6002333.html
Copyright © 2011-2022 走看看