Tuesday, September 13, 2011

How to change the font size or font name in static control?

How to change the font size, font name or font color in static control design by VC6.0 with win32 application environment.How to change the font size or font name in static control?
If you're in MFC, add a DDX_Control variable map using ClassWizard. Otherwise, get the HWND of the static control by passing its identifier to HWND GetDlgItem(UINT).



Create a font using the CreateFont function. Pass a size calculated by this formula:



-MulDiv(height_in_points, GetDeviceCaps(hdc, LOGPIXELSY), 72)



You can pass zeroes for most of the parameters of CreateFont. Finally, send WM_SETFONT to the static control:



SendMessage(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(1, 0));



I recommend keeping the font handle around so you can destroy it using DeleteObject when the dialog closes.

No comments:

Post a Comment