Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Application - DPI Issues

Tags:

windows

dpi

mfc

We are having a problem with one of our existing Win32 MFC based applications. It does not render correctly on displays that use high dpi settings. More specifically in Windows XP with 120 dpi selected, there are several places in the app where the text scales up but not their containers (text overflowing the bounds of it's button, etc). This also occurs in Windows 7 (and Vista) when >96 dpi is selected and "use XP style dpi scaling" is selected. If xp style scaling is not selected then I understand Win7 uses DPI virtualization instead. Everything looks fine when using DPI virtualization (Ok things are blurry but at least they're correct). By default in Win7 120 dpi uses xp style scaling and the next setting (144 dpi) does not. So our app looks correct at 144 dpi but wrong at 120 dpi.

If I edit the applications manifest to declare the app as "DPI aware" then this turns of DPI virtualization (but not XP style dpi scaling) and this gets me no where. Things still look really bad (no change for 120 dpi, 144 dpi now broken).

I need to fix this problem and I've tried reading up on DPI/scaling issues in general and it has been a learning experience. So far I have not found a suitable solution. At the moment I currently have no intention of doing a thorough and correct fix (the app correctly scales all elements according to the dpi). That would involve a LOT of rewriting. I think there are really two possible solutions. One is turn off any sort of DPI scaling all together. That would mean that if a users Win7 system was set to 120 dpi then everything on their system would look good/big but our app would look correct but would be small compared to everything else in other apps. The second solution would be to some how force our app to use DPI virtualization but to never use XP style dpi scaling. I want this to be an application side change and not rely on end users to have to make Windows configuration changes.

So far I have not found a way to accomplish either solution.

Can someone more knowledgeable on this subject please respond and point me in the right way?

Thanks

like image 637
Brad Avatar asked Nov 04 '22 11:11

Brad


1 Answers

You cannot force DPI Virtualization on 120 DPI settings. I have investigated this for a product myself because having the fuzzy look in high DPI seemed a good tradeoff.

We ended up making a full rewrite of the UI positioning and scaling to have it scale properly with the font scaling in high DPI settings. The client is now fully DPI aware and scales properly in any DPI setting.

The work to do this properly took one guy ~3 months in our case for a pretty complex client.

We had a secondary plan that we never tried but it might work for you: At start-up read the DPI scaling factor of the OS. Then reduce all font instances you have by this factor so that when Windows scales the fonts up again they are back at the size where the UI can fit them. Of course users with high DPI settings will not get bigger fonts in your application but it will at least be usable.

like image 151
Erik Alsmyr Avatar answered Nov 15 '22 05:11

Erik Alsmyr