Create modified HFONT from HFONT

后端 未结 2 534
[愿得一人]
[愿得一人] 2020-12-31 05:55

I using the Win32 API and C/C++. I have a HFONT and want to use it to create a new HFONT. The new font should use the exact same font metrics except that it should be bold.

相关标签:
2条回答
  • 2020-12-31 06:33

    Something like this - note that error checking is left as an exercise for the reader. :-)

    static HFONT CreateBoldWindowFont(HWND window)
    {
        const HFONT font = (HFONT)::SendMessage(window, WM_GETFONT, 0, 0);
        LOGFONT fontAttributes = { 0 };
        ::GetObject(font, sizeof(fontAttributes), &fontAttributes);
        fontAttributes.lfWeight = FW_BOLD;
    
        return ::CreateFontIndirect(&fontAttributes);
    }
    
    static void PlayWithBoldFont()
    {
        const HFONT boldFont = CreateBoldWindowFont(someWindow);
        .
        . // Play with it!
        .
        ::DeleteObject(boldFont);
    }
    
    0 讨论(0)
  • 2020-12-31 06:36

    You want to use the GetObject function.

    GetObject ( hFont, sizeof(LOGFONT), &lf );
    
    0 讨论(0)
提交回复
热议问题