05-09-2025, 12:55 AM
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.)
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)
'First, hide the screen before making any DPI Awareness changes
$ScreenHide
Declare Dynamic Library "user32"
Function DPI& Alias SetProcessDpiAwarenessContext (ByVal dpiContext As _Offset)
End Declare
Const UNAWARE = -1, AWARE = -2, PER_MONITOR_AWARE = -3
Const PER_MONITOR_AWARE_V2 = -4, UNAWARE_GDISCALED = -5
result = DPI(AWARE) 'Change the DPI Awareness to the mode you want your program to run under.
'Note that this is a one time ONLY change. Once set, it can't be altered by any other process or
'future call to the routine. This is an OS feature and not something which can be changed by the
'programmer, or any QB64PE dev.
_Delay .2 'always nice for a slight delay in this type of thing to make certain windows has time to register changes.
Screen _NewImage(3840, 2160, 32) ' <-- set as desired here
_ScreenShow 'Show the screen after the awareness is set and the mode is created as you desire
_ScreenMove _Middle 'note that you can't move a hidden screen so place this AFTER the _ScreenShow if applicable
'note also that _FullScreen or any other type commands should come AFTER that _ScreenShow as well
'if you try them earlier, you're just asking for trouble. Just save yourself the headache and degugging
'and put any other graphic commands AFTER the _ScreenShow.
'Don't forget to load a font which is readable for the screen without automatic scaling in play
'on my laptop, it's 200% scaling so a 1920x1080 screen scales to fit my 3840x2160 screen resolution.
'so going by that logic, I'm just going to scale my normal 16 pixel font to be a 32 pixel font.
f = _LoadFont("courbd.ttf", 32, "monospace") '32 pixel (estimated) fontheight
_Font f
Print "Hello World"
'And after all this, my screen should look normal on my laptop, but have a 4k resolution.
'So I can display images to a much higher resolution without downscaling or losing any details.


