Question about Windows Font scaling

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Morat20
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Jan 07, 2014 8:43 pm

Question about Windows Font scaling

Post by Morat20 »

I've noticed something odd with some controls and Windows font scaling. Admittedly, this is an older version of wxWidgets (2.9.5), but it's what I'm stuck working with for the time being.

I've got a bunch of radioboxes. If I manually set the font size to something large and run it, the radioboxes size properly for the larger font size. All the text is shown, etc. That doesn't seem to be a problem with other controls. The menu bar resizes properly, wxTextControls resize, wxButtons resize, etc.

But if I just turn the Windows font size up to 125% or 150%, and run the program, the radioboxes DON'T show all the labels. They're truncated, the radiobox too narrow to contain all the labels. (To be specific: I am not changing the Windows font WHILE the program is executing. I change it, then run the program).

What's the difference between creating a radiobox with the SetFont() set to an arbitrarily large font size, and using a "normal" font size but setting the Windows font size to 150%? Why are all my radioboxes not properly expanding to accommodate the increased size of the selection labels under one case, but are under the other?

And more importantly -- how do I fix it?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about Windows Font scaling

Post by doublemax »

Is your application marked as "dpi aware" through the manifest?
I assume you're using sizers and no hardcoded values for position and/or sizes?

2.9.5 is pretty old indeed. I would suggest you make a small test with both 2.9.5 and the latest wx version from GIT. If the latest version fixes it, you should upgrade. There were many improvements related to "High DPI" support over the last few months. The changes in your code should be minimal.
Use the source, Luke!
Morat20
Knows some wx things
Knows some wx things
Posts: 41
Joined: Tue Jan 07, 2014 8:43 pm

Re: Question about Windows Font scaling

Post by Morat20 »

doublemax wrote: Thu Apr 30, 2020 8:05 pm Is your application marked as "dpi aware" through the manifest?
I assume you're using sizers and no hardcoded values for position and/or sizes?

2.9.5 is pretty old indeed. I would suggest you make a small test with both 2.9.5 and the latest wx version from GIT. If the latest version fixes it, you should upgrade. There were many improvements related to "High DPI" support over the last few months. The changes in your code should be minimal.
Yes, sizers and no hardcoded sizes or positions. That was the root of my confusion, as I just got done overhauling the whole thing to dynamic layouts primarily to support larger fonts.

As to the manifest -- Well, darn. That's going to be problematic, as I'm stuck with this version of the library for the near future (updating further means updating the very old-style event setups) and update our compiler, which is at least on the list.

I'm going to have to create a copy of my library and do some testing where I can't contaminate production code. Fantastic.

I don't suppose there's any way to override Window's increasing the font size, or at least limit it to something that works?
User avatar
doublemax
Moderator
Moderator
Posts: 19116
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Question about Windows Font scaling

Post by doublemax »

Does this affect only radio buttons? If yes, maybe you can find the patch that fixed this in wxWidgets and apply it to your 2.9.x version. E.g. i found this one, but i'm not sure if it's the correct one for your issue:
https://github.com/wxWidgets/wxWidgets/ ... db97f6ee87
Use the source, Luke!
art-ganseforth
Earned some good credits
Earned some good credits
Posts: 147
Joined: Mon Sep 01, 2014 10:14 am

Re: Question about Windows Font scaling

Post by art-ganseforth »

Probably i have a solution:

Declarations:

Code: Select all

#define _DPI_AWARENESS

// The function: SetProcessDPIAware seems to be missing
#ifdef __WXMSW__
typedef BOOL WINAPI (*SetProcessDPIAwareFunc)();
#endif

class clsApp : public wxApp {

private:
    void MSWEnableHiDPI()
    {
#ifdef __WXMSW__

        HMODULE m_user32Dll = LoadLibrary(L"User32.dll");
        if(m_user32Dll) {
            SetProcessDPIAwareFunc pFunc = (SetProcessDPIAwareFunc)GetProcAddress(m_user32Dll, "SetProcessDPIAware");
            if(pFunc) {
                pFunc();
            }
            FreeLibrary(m_user32Dll);
            m_user32Dll = NULL;
        }
#endif
    }
    
    [.YOUR CODE.]
};
wxApp::OnOnit():

Code: Select all

bool clsApp::OnInit() {  

#ifdef _DPI_AWARENESS
//--------- DPI-Awareness -------------------------------
       MSWEnableHiDPI(); // Enable HiDPI on Windows
#endif       
    
    [.YOUR CODE.]
};

On my Notebook this scales all wxFonts, but only fonts. So, fonts will be large in small windows on high-resoltion-displays.



Best,
Frank
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4193
Joined: Sun Jan 03, 2010 5:45 pm

Re: Question about Windows Font scaling

Post by PB »

art-ganseforth wrote: Fri May 08, 2020 5:17 pm Probably i have a solution:
Setting DPI awareness is normally not done in code but in the application manifest.

wxWidgets now have, unfortunately not perfect, per monitor DPI awareness support.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7459
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Question about Windows Font scaling

Post by ONEEYEMAN »

Hi, PB,
PB wrote: Fri May 08, 2020 6:03 pm
art-ganseforth wrote: Fri May 08, 2020 5:17 pm Probably i have a solution:
Setting DPI awareness is normally not done in code but in the application manifest.

wxWidgets now have, unfortunately not perfect, per monitor DPI awareness support.
I believe it is still WIP...

Thank you.
Post Reply