2

The default dialog box font in Windows is MS Shell Dlg.

I don't like it, because it's not correct.

It's easy to manually change the font of a single dialog item, but how do I display a dialog box with the "correct" system font (from lfMessageFont) applied to all of its controls by default (not manually) when calling DialogBox (or using ATL/WTL)?

Note:

The reason I've said "not manually" so many times is that I am looking for a solution better than looping through everything with EnumChildWindows (or the like). Does one exist?

Community
  • 1
  • 1
user541686
  • 205,094
  • 128
  • 528
  • 886
  • I think you need to enable visual styles in your manifest. http://msdn.microsoft.com/en-us/library/bb773175(v=vs.85).aspx Have you done that? – i_am_jorf Aug 28 '11 at 05:33
  • @jeffamaphone: Yes I have. It has nothing to do with that, it's the text `MS Shell Dlg` embedded in the dialog resource that's the cause. I just don't have an elegant solution for changing it at run time. – user541686 Aug 28 '11 at 05:34
  • Since you're loading the dialog from a template in the resource file, have you considered just changing the template? You can say `FONT 8, "your desired font here"` just before `BEGIN`. – i_am_jorf Aug 28 '11 at 05:40
  • 1
    @jeffamaphone: How am I supposed to know the user's font at compile-time? – user541686 Aug 28 '11 at 05:43
  • Okay, I think I understand now. See answer below. – i_am_jorf Aug 28 '11 at 06:04

1 Answers1

2

From About Dialog Boxes:

The system font can vary between different versions of Windows. To have your application use the system font no matter which system it is running on, use DS_SHELLFONT with the typeface MS Shell Dlg, and use the DIALOGEX Resource instead of the DIALOG Resource. The system maps this typeface such that your dialog box will use the Tahoma font. Note that DS_SHELLFONT has no effect if the typeface is not MS Shell Dlg.

I think this is what you want. If that doesn't work, then I guess you'll have to load the resource manually and modify the template before passing it to DialogBox.

i_am_jorf
  • 53,608
  • 15
  • 131
  • 222
  • Nope, that doesn't work for some reason; I've already tried it. Loading the resource manually seems painful and seems to be the wrong way to go about doing it (especially because it doesn't fit into the ATL/WTL design, although that's something I could bypass)... is there really no better way? – user541686 Aug 28 '11 at 06:06
  • There is this guy who suggests an MFC way to do it: http://neelaakash.wordpress.com/2007/12/31/change-default-dialog-font-of-cdialog/ There is also the MFC CWindow::SendMessageToDescendents: http://msdn.microsoft.com/en-us/library/st4w55wa.aspx – i_am_jorf Aug 28 '11 at 06:08
  • Those are all the ways I can find. Doesn't mean there isn't a way, but it should be automatic. Do you get properly styled buttons (i.e. are you sure you have the manifest stuff correct)? – i_am_jorf Aug 28 '11 at 06:09
  • WOWWWW... great job Microsoft at using this internally and NOT documenting it!! :( I had never seen that before, and it seems like the MFC way is *made* to accomplish this task. Thanks a lot for the link, that's really helpful (even though I'm using ATL)! +1 (And yes, I got nice buttons and everything, the manifest stuff is correct. :P) – user541686 Aug 28 '11 at 06:12
  • 2
    How do you know that your dialog is compatible with the metrics of an unknown font? What if the users font has metrics that result in your template generating a dialog with truncated text? note also that the message box font is not the same as the system dialog font. It sounds like you want your dialog to use the message box font, which means that it will look different from all other dialogs in the system. – Raymond Chen Aug 28 '11 at 15:38
  • MS Shell Dlg **2** works perfect for me. [MSDN says](https://learn.microsoft.com/en-us/windows/win32/intl/using-ms-shell-dlg-and-ms-shell-dlg-2): *MS Shell Dlg 2 face name was introduced in Windows 2000 to support the look that was introduced with Windows 2000*. Guess I’ll file a bug against the docs for being 20 years outdated … – Krishty Feb 05 '20 at 13:23