Has anyone implemented Windows calls from LabVIEW to read and change the Windows Display Scaling?
Solved! Go to Solution.
The smart-a** answer: I'm trying to change the display scaling in Windows from LabVIEW.
Perhaps a more informative answer: My client bought a Surface with 1800 x 1200 res, but the screen is only 10". (Seems like less. It's really small.) (This would be a great place to interject Michael's running joke from the Office, but I'll refrain...) (Does that count as refraining?) To run any normal Windows program, it's best to leave the scaling at 150%. But LabVIEW doesn't play well with the scaling factor, and I've already spent a lot of time laying out the UI to fit 1800 x 1200. So I'd like to have the laptop configured for 1800 x 1200 with 150% scaling, then have my program change the scaling to 100%. When my program exits, I would set it back to whatever it was before my program started, hence the need to be able to read as well as write the scaling factor. In case the end user decided to change the scaling for his/her other apps.
I guess this would only work well if that was the only application the user was running at the time.
From my limited research some time ago, Microsoft really does not want an application to be able to mess with that system setting. From a system perspective this is quite understandable as if they start to document any API to to that, every half baked programmer will feel eligible to change that setting at will.
And that can really mess with application on a system depending if they are DPI aware or not. Actually it will mess in any case with applications but in different ways, depending on their DPI awareness. LabVIEW being fully not DPI aware in any way is at one extreme of that scale, while other applications being partly or fully DPI aware are affected in even worse ways when the DPI scaling changes as they will autimatically try to adjust to that, more or less successfully depending on their awareness. Unpretty effects are unavoidable during the switch and some may remain after for such applications.
You may rather want to play with the process DPI aware setting for your LabVIEW application instead of changing that system setting. There is an API SetProcessDpiAwarenessContext() that lets you change the setting for the current process. LabVIEW is by default DPI unaware and hence Windows will scale its Windows with the DPI scaling factor automatically. Lieing to Windows that your LabVIEW process is DPI aware, either system DPI aware or even per monitor will tell Windows to not scale any LabVIEW Windows. But above mentioned API has one drawback, at the time your LabVIEW application gets a change to call it, it most likely has already called various Windows graphic IO functions and Windows has determined the DPI mode already and you can't change that mode after it has been set once. Microsofts solution for that is to rather use a manifest file. For LabVIEW you can do that by placing a MyApp.manifest file with the necessary contents into the same directory as your executable.
See here about the process. This method has the advantage that it does not mess with your users system settings.
Thanks for the info, Rolf. Much appreciated, as always.