How can I specify a font for a window created through CreateWindow?

前端 未结 3 2166
无人及你
无人及你 2021-02-19 04:15

I\'m creating window using pure Win32 API (RegisterClass and CreateWindow functions). How can I specify a font for the window instead of system defined one?

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-19 04:56

    As vividos said just use CreateFont()/CreateFontIndirect:

    HFONT hFont = CreateFont (13, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET, 
          OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, 
          DEFAULT_PITCH | FF_DONTCARE, TEXT("Tahoma"));
    

    And then set this font for your window/control with the WM_SETFONT message:

    SendMessage(window, WM_SETFONT, hFont, TRUE);
    

提交回复
热议问题