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
  • 相关阅读:
    MES取所有部门的函数实例
    MES总结:CBF.Common 文件Net下的有类型转换
    LINQ to SQL 系列 如何使用LINQ to SQL插入、修改、删除数据
    c# abstract抽象类与继承类子类的构造函数_base
    C# 之泛型详解
    MVC6与Asp.net5
    MenuStrip菜单递归
    .net 下的MVCPager
    UVALive5461 UVA615 POJ1308 HDU1325 Is It A Tree?
    UVALive5461 UVA615 POJ1308 HDU1325 Is It A Tree?
  • 原文地址:https://www.cnblogs.com/findumars/p/6002333.html
Copyright © 2011-2022 走看看