Search code examples
c++winapifonts

win32 - Using the default button font in a button


I'm creating a small WinAPI application in C++. I am trying to create a button on my form by using the code:

HWND hwndButton = CreateWindow(
    TEXT("BUTTON"),   
    TEXT("Click Here"),       
    WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON,  // Styles 
    10,         
    10,         
    100,        
    30,        
    hwnd,     
    NULL,       
    (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE),
    NULL);     

This code is based off of an MSDN sample. My issue is that it uses a bold font on the button like this:

enter image description here

When I want to use the standard font like this:

enter image description here

I already have the preprocessor directive at the top of my file to enable visual styles.

#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

What steps should I take to use the standard system wide font?

Thanks


Solution

  • There's no such thing as default system wide font for controls, initially you get a control created with "System" font, that's what you see on first picture. When button is created as part of a dialog, it uses a font from dialog template, so using something like "MS Shell Dlg" with appropriate size + WM_SETFONT on a button should give you the same result as on picture 2. Note that there's no physical MS Shell Dlg font on a system, it's mapped to particular font according to registry settings.

    Common control manifest has nothing to do with this, behavior has not changed with comctl32 version 6.