Reputation: 11
how do you change the font size of a static text box in a Windows GUI application written in C++?
HWND hText = CreateWindowW(L"EDIT", L"enter some text", WS_VISIBLE | WS_CHILD | ES_RIGHT, 100, 100, 100, 50, hWnd, NULL, NULL, NULL);
do i have to make another Window message
Upvotes: 1
Views: 2568
Reputation: 6289
As @RbMm said that, use CreateFont
and WM_SETFONT
can achieve this. And the official documents also have corresponding introduction.
Changing the Font Used by an Edit Control.
An application can change the font that an edit control uses by sending the WM_SETFONT message. Most applications do this while processing the WM_INITDIALOG message. Changing the font does not change the size of the edit control; applications that send the WM_SETFONT message may have to retrieve the font metrics for the text and recalculate the size of the edit control. For more information about fonts and font metrics, see Fonts and Text.
The least code:
LOGFONT logfont;
ZeroMemory(&logfont, sizeof(LOGFONT));
logfont.lfCharSet = DEFAULT_CHARSET;
logfont.lfHeight = -20;
HFONT hFont = CreateFontIndirect(&logfont);
SendMessage(hText, WM_SETFONT, (WPARAM)hFont, TRUE);
Upvotes: 3