PDA

View Full Version : n = WinSetProcessDPIAware()



catventure
13-03-2024, 10:10
I saw that in the latest version of thinbasic there is a new function


n = WinSetProcessDPIAware()


My TAB adventure program was made using thinbasic core 1.9.16.17. for backwards compatibility with Windows XP and above.


A user of my program tested on his system and reported that even on a low end laptop with win 10 and a full HD screen (1920 x 1080) there were readability problems due to display size of the TAB app.




The text in the editor where you type the info for location text is literally unreadable it is so small. And the game text in the runner is literally unreadable and too small.


TAB seems very fast and the editor looks awesome, for what I can see. Unfortunately the text aspect of TAB is not compatible with modern systems. A shame, because otherwise TAB appears awesome in reading through the features.


it is difficult trying to find something that still works and that works with modern systems and is DPI aware and will display properly on modern systems."



Since I cannot use the new DPI function available in the new thinbasic version, what equivalent code would I need to include to update my program so that it will be dpi (dots per inch) aware and automatically adjust to the screen resolutions and monitor displays of the more modern high end setups of today?


It would be great if in fact possible to do? How would I achieve it - and whereabouts would I position the code in my program listing?
(I'm assuming it would need to be set as a default before the program creates any Windows)


I am only a hobbiest programmer and after reading the microsoft link in the thinbasic help file for the new function I do not understand or see how I would begin to implement it correctly into my code.


MS documentation at:
https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setprocessdpiaware



I would really like it if my program could be usable on as many Windows rez as possible. Seems later setups have changed gradually over the years to higher settings than the default standard 96dpi :)


Regards,
catventure/Philip.

ErosOlmi
14-03-2024, 08:04
Ciao,

you can try the following call that tells the operating system that your application is not dpi aware

https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-setprocessdpiawareness


'Declare Function SetProcessDPIAware Lib "user32.dll" Alias "SetProcessDPIAware" () As Long
%PROCESS_DPI_UNAWARE = 0
%PROCESS_SYSTEM_DPI_AWARE = 1
%PROCESS_PER_MONITOR_DPI_AWARE = 2
Declare Function SetProcessDpiAwareness Lib "Shcore.dll" Alias "SetProcessDpiAwareness" (byval PROCESS_DPI_AWARENESS as dword) As Long
SetProcessDpiAwareness(%PROCESS_DPI_UNAWARE)


If it works, you can add a parameter to your application to call or not this function depending on some circumstances.

Let me know
Eros

catventure
20-03-2024, 19:59
Hi Eros,


Thank you for your response.


I placed this code into my program listing near the top and my program ran as normal.




%PROCESS_DPI_UNAWARE = 0
%PROCESS_SYSTEM_DPI_AWARE = 1
%PROCESS_PER_MONITOR_DPI_AWARE = 2
Declare Function SetProcessDPIAware Lib "user32.dll" Alias "SetProcessDPIAware" () As Long




The other bit of code you supplied did not




%PROCESS_DPI_UNAWARE = 0
%PROCESS_SYSTEM_DPI_AWARE = 1
%PROCESS_PER_MONITOR_DPI_AWARE = 2
Declare Function SetProcessDpiAwareness Lib "Shcore.dll" Alias "SetProcessDpiAwareness" (byval PROCESS_DPI_AWARENESS as dword) As Long
SetProcessDpiAwareness(%PROCESS_DPI_UNAWARE)



(Invalid. Didn't recognise Lib "Shcore.dll)


I understand that If the dpi setting is >96 then no doubt it will be required to make the TAB program dpi aware.


This could mean devising code to take into account the different versions of windows that might be running the program....?


I also accept that some GUI elements and fonts might need to be scaled somehow - so might need to get the current desktop dpi ratios from the monitor...


Sounds though like it might be a little complicated - but maybe possible to implement this.

How and what code do I need to do it? Any help suggestions would be great.


If TAB is not dpi aware then Windows will probably scale it resulting in smaller gui, images and text.


When I created my program all those years ago I did not envisage this problem of visibility or usability occurring on the high end monitor resolutions which are slowly becoming default on newer setups nowadays.




Thanks ever so much,
catventure/Philip.