![]() |
|
WINDOWS Set DPI Awareness - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26) +---- Forum: SMcNeill (https://qb64phoenix.com/forum/forumdisplay.php?fid=29) +---- Thread: WINDOWS Set DPI Awareness (/showthread.php?tid=3672) |
WINDOWS Set DPI Awareness - SMcNeill - 05-08-2025 Code: (Select All)
With the above, a windows user can set DPI Awareness as they wish for their programs. Note that once Awareness is turned off, the system ignores all other calls so you can't just turn it off and on all willy-nilly. And what *IS* DPI Awareness? It's the automatic scaling of a program according to the settings you have in your window display settings. For example, if you have your system set to 200% scaling, it's going to automatically scale all your programs 200% in size. For a 3840 x 2160 display, this means that the biggest program screen you can make and view would be 1920 x 1080 as it'd scale 200% to fill the 3840 x 2160 display completely. So with this, you can set your program to decide if it wants to do that scaling or not. If your program is DPI(Aware), it means you're going to do any necessary scaling yourself. If it's DPI(UnAware), it means you're going to let the system do that automatic scaling. By monitor is going to depend on your scaling settings on each monitor and where the program is located on the desktop. Chances are, if you don't know what DPI Awareness is or that Windows automagically resizes and scales things for you, then you won't need to worry about this. This is mainly something that affects people with scale factors built into their system (like many laptops -- mine defaults to 200% scaling) and if you've never noticed it in the past, then it's probably not something you need to concern yourself about anytime soon.
RE: WINDOWS Set DPI Awareness - James D Jarvis - 05-08-2025 Thank you. I was just messing about with DPI-aware controls in a another programming package. This is more impressive in windowed mode. Now I can actually create a program that's the real screen width of my system (or closer to it), without having to mess with settings. Thanks again. RE: WINDOWS Set DPI Awareness - Jack - 05-08-2025 thank you Steve how about a cross-platform solution
RE: WINDOWS Set DPI Awareness - SMcNeill - 05-08-2025 (05-08-2025, 08:32 PM)James D Jarvis Wrote: Thank you. I was just messing about with DPI-aware controls in a another programming package. One thing to note -- you may want to set $SCREENHIDE at the start of your program, before you set the DPI Awareness. The Windows documentation reads: Quote:You must call this API before you call any APIs that depend on the DPI awareness (including before creating any UI in your process). So technically you're supposed to call this before making any graphical windows and such, to prevent problems. I'd suggest something like: Code: (Select All)
(OR similar. I haven't actually tested the above, so just use it as an illustration of the program flow you'd want to set up. If that doesn't work on the first try, look up the SCREENHIDE and SCREENSHOW examples on the wiki and sort out whatever quirk I may have missed in the proper syntax/usage.) (05-08-2025, 08:39 PM)Jack Wrote: thank you Steve Wish I could, but I'm a windows user. I know about squat about linux/mac, but I imagine they'd be quite a bit more difficult to sort out. Linux is definitely gonna be a cluster since there's both X and Wayland and they handle it differently. I'll leave it to the other devs to sort those OSes out. Best I can do is offer this little tidbit for our windows' users.
RE: WINDOWS Set DPI Awareness - SMcNeill - 05-09-2025 A tested and running version, which I commented fairly extensively for everyone. If someone has troubles with this after this... It's probably an OS issue. This won't work on any version of Windows prior to Windows 10. It won't work on Linux or Mac. DPI Awareness is a relatively new thing and older versions of windows didn't have it. (At least not this many options of it, it dates back to Win 8, IIRC.) The basic concept is: Hide the screen. Set the DPI Awareness. Set the Desired Screen. Unhide the screen. Then move/tweak the screen with other commands as desired. Working demo is below. (Resolutions may need changing as this is what my laptop has for max settings and what I tested it on. Your own laptop/monitor/system may very well be configured differently.) Code: (Select All)
|