The application loads the external font file (using the AddFontResource API function to specify the font)

Source: Internet
Author: User


[CPP]
View PlainCopy
  1. /*
  2. Msdn:
  3. Any application this 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_BROADC Ast.
  4. When an application no longer needs a font resource then it loaded by calling the AddFontResource function, it must remove That's resource by calling the RemoveFontResource function.
  5. This function installs the font is the current session. When the system restarts, the font is not being present. To has the font installed even after restarting the system, the font must is listed in the registry.
  6. */
  7. Defined as member variable
  8. CFont font;
  9. TCHAR Szpath[max_path];
  10. initialization function
  11. _tcscpy (szpath, _t ("%s"), _t ("F://11.ttf"));
  12. LOGFONT LF;
  13. Lf.lfheight = 60;
  14. Lf.lfwidth = 30;
  15. lf.lfescapement = 0;
  16. lf.lforientation = 0;
  17. Lf.lfweight = 90;
  18. lf.lfitalic = 0;
  19. Lf.lfunderline = 0;
  20. lf.lfstrikeout = 0;
  21. Lf.lfcharset = Default_charset;
  22. lf.lfoutprecision = 0;
  23. Lf.lfclipprecision = Clip_stroke_precis;
  24. lf.lfquality = 0;
  25. lf.lfpitchandfamily = 0;
  26. _tcscpy (Lf.lffacename, _t ("XXX")); //This is the font name
  27. Font. CreateFontIndirect (&LF);
  28. ASSERT (font. Getsafehandle ());
  29. You can then call the following code to set the font
  30. if (! AddFontResource (szpath))
  31. {
  32. AfxMessageBox (_t ("Load font failed."));
  33. return;
  34. }
  35. :: SendMessage (Hwnd_broadcast, wm_fontchange, 0, 0);
  36. GetDlgItem (IDOK)->setfont (&font);
  37. Release font resources When you don't need them at the end
  38. RemoveFontResource (szpath);

http://blog.csdn.net/visualeleven/article/details/6248115

The application loads the external font file (using the AddFontResource API function to specify the font)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.