none
如何添加字体? RRS feed

  • 问题

  • 在开发过程中?如何利用AddFontResource这个函数加入自己想添加的字体?


    AddFontResource(L"Digit.ttf");

    SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);

    GetLocalTime(&curTime);

    GetTimeFormat(LOCALE_SYSTEM_DEFAULT, 0, &curTime,L"hh':'mm':'ss tt" , STR, 12);

    Snumber = GetDeviceCaps(NULL, LOGPIXELSY);

    winRect.bottom = DRA:Tongue TiedCALEY(60);

    LOGFONT lf;

    HFONT hFontNew=NULL;

    HFONT hFontOld=NULL;

    memset(&lf, 0, sizeof(LOGFONT));

    WCHAR lffn[]= TEXT("Digit");

    wcscpy(lf.lfFaceName,lffn);

    GetObject((HFONT)GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);

    lf.lfHeight = -((12*GetDeviceCaps(NULL, LOGPIXELSY))/72);

    hFontNew = CreateFontIndirect(&lf);

    hFontOld = (HFONT) SelectObject(dc, hFontNew);

    DrawText(dc, STR, wcslen(STR), &winRect,DT_SINGLELINE | DT_VCENTER | DT_CENTER);

    hFontNew = (HFONT) SelectObject(dc, hFontOld); 

    DeleteObject(hFontNew);

    RemoveFontResource(L"Digit.ttf");

    我用了以上代码,但是还是添加不上,有人知道哪里错了,请告诉我,多谢了~
    2008年9月11日 3:03

答案

  • See:

    http://fabdecret.blogspot.com/2007/07/install-unicode-fonts.html

    And to see the documentation on AddFontResource, The parameter is the path to the font file.  The return value is the number of fonts added.  if you've copied the font to the \Windows\Fonts folder, I don't think that you need to call AddFontResource, anyway.  It's used to register a new font file for the system.  Once it's done, the font name found inside that font file should work when calling the Font( string, ... ) version of the Font constructor.

     

    Good luck~


    2008年9月15日 5:17
    版主

全部回复

  • 真的没有人知道吗?这个FONT是加进去了,返回值为1,但是不知道为什么画的时候,还是用系统的字体画的
    2008年9月12日 6:16
  • See:

    http://fabdecret.blogspot.com/2007/07/install-unicode-fonts.html

    And to see the documentation on AddFontResource, The parameter is the path to the font file.  The return value is the number of fonts added.  if you've copied the font to the \Windows\Fonts folder, I don't think that you need to call AddFontResource, anyway.  It's used to register a new font file for the system.  Once it's done, the font name found inside that font file should work when calling the Font( string, ... ) version of the Font constructor.

     

    Good luck~


    2008年9月15日 5:17
    版主
  • Thx,this issue has been sloved.
    2008年9月17日 10:50