Windows scaling for AHK GUIs

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Logitope
Posts: 19
Joined: 13 Feb 2021, 14:44

Windows scaling for AHK GUIs

27 Nov 2021, 22:53

I have a script with GUI optimized for FullHD resolution. If I run it on 4K screens with Windows scaling set to more than 100% (in Windows 10 option "Change the size of text, apps, and other items" in Display settings), problems arise:

- When using the right-click context menu, the mouse pointer jumps and the context menu doesn't appear where the mouse was clicked.
- Some GUIs are not scaled properly so that some buttons are not visible.

One approach to fix this would be using:
Gui, -DPIScale
The GUIs are then not scaled. However, the fonts are still scaled, so these would need to be adjusted. I found some older threads on how to do that dynamically (not sure if the approach would be exactly the same on Win 10):

https://www.autohotkey.com/board/topic/88097-large-system-fonts-in-win7-overrides-gui-font-size/
https://www.autohotkey.com/board/topic/90306-solved-gui-text-and-dpi-scaling-in-windows-larger-text-120-dpi/

I haven't tried this approach yet because I would prefer to keep scaling. On 4K notebooks, it's not uncommon to set scaling to 250%, so if scaling is suppressed, the GUIs become quite small compared to the appearance on large FullHD screens.

I have noticed the following behavior which I assume affects all AHK scripts (I am not posting my code as it is long and probably not related to the problem):

If I change the Windows scaling setting after the script was started, everything works perfectly: GUIs and fonts are scaled properly and the context menu doesn't jump either. Only if the setting was already above 100% when the script is started, the mentioned problems arise.

So I am hoping it is possible to somehow trick the script into behaving as if the setting was changed after it was started. Apparently Windows is capable of scaling AHK GUIs including fonts properly, as this happens when changing the setting with the script running.

I am hoping someone with more knowledge of how Windows handles this can help.
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Windows scaling for AHK GUIs

28 Nov 2021, 06:51

You indicate that some buttons are not visible, mouse pointer jumps, and context menu does not appear in the right place. These likely relate to how you have set up your script. There may be better ways to approach it. Feel free to post your script for feedback about it.
Logitope
Posts: 19
Joined: 13 Feb 2021, 14:44

Re: Windows scaling for AHK GUIs

28 Nov 2021, 11:30

mikeyww wrote:
28 Nov 2021, 06:51
These likely relate to how you have set up your script.
Thanks for steering me in the right direction! I had assumed that the jumping context menu was a general problem, but on looking at my code again I quickly realized the problem and I was able to solve it in two ways.

For reference, the problem was the following line which I used to determine which item of a listbox the user right-clicked on (basically I set up a typical context menu with options to open, delete files etc.):

Click A_GuiX, A_GuiY

The problem was that the values of A_GuiX and A_GuiY are not automatically adjusted by DPIScaling. I fixed it by (1) manually adjusting the coordinates (commented-out part below) and (2) switching DPIScaling off and on again. I'll stick with the second version as the DPI value in the manual is said to be 96 only on "most systems".

Code: Select all

MainGuiContextMenu:
Gui, Main:Submit, NoHide
/*
XCoordinate := A_GuiX * A_ScreenDPI/96
YCoordinate := A_GuiY * A_ScreenDPI/96
Click, %XCoordinate%, %YCoordinate%  ; this selects the relevant listbox item.
*/
Gui, -DPIScale
Click A_GuiX, A_GuiY
Gui, +DPIScale
Menu, %A_GuiControl%_Context, Show
Return
Regarding the GUIs with missing buttons, I should be able to find a solution as well.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, arcylix, drani, Nerafius, Rohwedder and 218 guests