How to change the font style of the dialog's title bar in MFC

后端 未结 1 409
无人及你
无人及你 2021-01-22 07:33

By default in MFC, the font of the dialog\'s title bar is in correspondence with the system settings. How can I change the font style?

相关标签:
1条回答
  • 2021-01-22 07:55

    This is not just an MFC default; it works that way for all Windows applications. That's because the operating system draws the title bar for all windows, and naturally the operating system respects the settings that the user has configured.

    If you want to change that and override the user's settings (and I really question why you would want to do such a thing), then you will need to take the drawing of the window's entire non-client area (which includes the title bar) into your own hands. This is achieved by handling the WM_NCPAINT message (or I suppose in MFC, handling a member function of your window named something like OnWmNcPaint).

    But be forewarned: this is a fairly advanced task, and difficult to get right. Additionally, it will break the glass styling and other translucent effects of the Aero theme. I have no idea what it does on Windows 8 since I haven't tried it yet, but I imagine it breaks things there, too.

    To make it work properly with the Aero theme, you will need to detect at runtime whether Aero is enabled, and if it is, jump through some additional hoops. If the Aero theme is not enabled, then you fall back to the old method of handling the WM_NCPAINT message.

    Did I mention that I don't recommend this? There's a reason that this is a global system setting, not something intended to be overridden by applications. If the user wants to use an ugly font in their title bars, then that is their prerogative.

    0 讨论(0)
提交回复
热议问题