Window with SysMonthCal32 class doesn't respond to WM_SETFONT

374 Views Asked by At

I'm not sure what am I doing wrong. I have a functionality in my CDialog-based MFC app to increase the font in some common controls. It is done by sending them WM_SETFONT message with a larger font:

//No error checks for brevity

HFONT hFnt = (HFONT)::SendMessage(hCtrlWnd, WM_GETFONT, 0, 0);

LOGFONT lfFont;
::GetObject(hFnt, sizeof(lfFont), &lfFont);

BOOL bPositive = lfFont.lfHeight >= 0;
long nFontSz = abs(lfFont.lfHeight);
nFontSz += nFontDelta;
lfFont.lfHeight = bPositive ? nFontSz : -nFontSz;

HFONT hNewFont = ::CreateFontIndirect(&lfFont);

::SendMessage(hCtrlWnd, WM_SETFONT, (WPARAM)hNewFont, TRUE);

//Need to DeleteObject hNewFont when control gets a new font or is destroyed

This works for most controls except the DateTime picker (or to be more precise, its month-calendar, SysMonthCal32 window class.)

Here's a screenshot on Windows XP, where it works as expected:

Normal magnification:

enter image description here

Enlarged:

enter image description here

But here's what I get on Windows 10, normal magnification:

enter image description here

And (supposed to be) enlarged, but isn't:

enter image description here

So why is it working on XP and stops, starting from Vista onward?

1

There are 1 best solutions below

2
Axalo On

You are probably using ComCtl32.dll version 6 which uses the Visual Styles API.
This means that most text is drawn by either DrawThemeText or DrawThemeTextEx.
Both of these functions use the font specified by the HTHEME argument.

To change the font you could either change the window's theme using SetWindowTheme or use a version of ComCtl32.dll prior to version 6.

The handling of WM_SETFONT and WM_GETFONT seems to be for keeping compatibility with programs that use these messages to store their font. They are not actually used for drawing.