0

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?

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • This is only a guess, but it might simply not respond (for gui consistness reasons) to WM_SETFONT; Try changing it's visual theme. – Michael Chourdakis Mar 17 '19 at 10:10
  • The font can be changed by removing the theme in DTN_DROPDOWN, but the calendar must be resized, from my tests. A big font on Windows 10 : [Test DTP font](https://i.ibb.co/QXqTcTd/DTP-2.jpg) – Castorix Jun 25 '19 at 19:03
  • @Castorix: Hmm, interesting, Thanks. Can you show how you removed its theme? Also what would happen if you add it back after resizing? (Also, I'm assuming that you resize it after retrieving its ideal size with `MCM_GETMINREQRECT`, right?) If it's easier, I have an email addr in my profile. Thanks. – c00000fd Jun 25 '19 at 19:25
  • 1
    The test I did : I changed the font with DateTime_SetMonthCalFont after its creation, then in DTN_DROPDOWN I get the MonthCal handle with DTM_GETMONTHCAL, I remove the theme with SetWindowTheme(hWndMonthCal, L"", L""); and I resize the container window with MoveWindow(GetParent(hWndMonthCal), 0, 0, 600, 400, TRUE); (600, 400 is for testing, those values must in fact be big enough to force a resize) – Castorix Jun 25 '19 at 19:42
  • @Castorix" what happens if you then call `SetWindowTheme(hWnd, L"EXPLORER", NULL)` on it after resizing? – c00000fd Jun 25 '19 at 20:07
  • The original theme comes back with the original theme font... – Castorix Jun 25 '19 at 20:12
  • @Castorix: and does the font size remain large? – c00000fd Jun 25 '19 at 21:03
  • No, the new font is only used when the control has no theme (like when it is created with CC. v. 5) – Castorix Jun 25 '19 at 21:50
  • @Castorix: yeah, thanks, It looks like there's some kinda bug in the `SysMonthCal32` WndProc logic when dealing with themes and fonts. – c00000fd Jun 26 '19 at 00:57

1 Answers1

0

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.

Axalo
  • 2,953
  • 4
  • 25
  • 39
  • Hmm ... except that every other control that has visual themes works with the `WM_SETFONT`, except that one. – c00000fd Mar 17 '19 at 19:41
  • There are [dozens](https://learn.microsoft.com/en-us/windows/desktop/controls/individual-control-info) of controls, of which only about half support changing the font when drawn with visual styles. The month calendar class doesn't seem to be one of them. Subclassing the control and temporarily hooking `DrawThemeText` during `WM_PAINT` might also work. – Axalo Mar 17 '19 at 20:24