开发者

Changing font smoothing for my application alone and not the global windows font smoothing settings

I have a Windows application written in C++, and using Win32-API. I wa开发者_运维问答nt to change the font smoothing of my application programmatically, thus allowing the user of my application to choose between "none", "standard", and "cleartype".

I use SystemParametersInfo(SPI_SETFONTSMOOTHING, ... ) to change the smoothing type, however this changes the global system settings of Windows, and effects all other applications. Is there any way to change the smoothing for my application alone?

Edit: Clarification - I'm embedding another window within my window, and thus I have no control over the fonts within the embedded window.

Thank You


Maybe there's an easier way but one way is to change all the fonts which you paint with, and which all your controls use, to ones with anti-aliasing turned off.

You can use WM_GETFONT and WM_SETFONT to get/set the fonts used by most controls (they both use HFONT object handles).

You can use GetObject to get a LOGFONT structure for an HFONT, then adjust the anti-aliasing flags on the LOGFONT, then create a new HFONT via CreateFontIndirect. (Don't forget to destroy the font somewhere, after no control is using it anymore.)

It's also worth keeping in mind that some fonts may force anti-aliasing or cleartype to be on. So you may need to change the font name as well as the flags when editing the LOGFONT structure.


On modern displays with DPI setting and Windows 10, even with ClearType enabled, fonts may look blurry. I've spent several hours figuring out why a simple Win32 application does have a cool thin system font in window decoration, and the same font ugly blurred in the client area. The keyword is dpiAware. Adopt the code below for your application manifest, and the problem will get solved:

<assembly
    xmlns="urn:schemas-microsoft-com:asm.v1"
    xmlns:asmv3="urn:schemas-microsoft-com:asm.v3" manifestVersion="1.0">
<assemblyIdentity
    version="1.0.0.0"
    processorArchitecture="AMD64"
    name="Scintilla.SciTE.SciTE"
    type="win32"
/>
<trustInfo
xmlns="urn:schemas-microsoft-com:asm.v3">
  <security>
    <requestedPrivileges>
      <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
    </requestedPrivileges>
  </security>
</trustInfo>
<asmv3:application xmlns="urn:schemas-microsoft-com:asm.v3">
    <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
        <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True/PM</dpiAware>
    </asmv3:windowsSettings>
</asmv3:application>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜