Get DPI Scaling Awareness level? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Flowgun
Posts: 75
Joined: 25 Aug 2022, 09:42

Get DPI Scaling Awareness level?

Post by Flowgun » 30 Mar 2023, 15:11

Hello,

I'm writing a window manager/snapper, and I noticed that when I have two screens with different DPI values, when I move windows using "WinMove", some windows start to automatically resize uncontrollably as soon as they start touching the other screen (ex: Chrome). On the other hand, other applications like Notepad++ behave as expected, keeping their initial size.
When I add this DllCall, the behaviors are reversed (chrome not resizing, but Notepad++ resizing):
DllCall("SetThreadDpiAwarenessContext", "ptr", -4, "ptr")

This behavior seems to be because Notepad++ is not DPI-aware while chrome is.
Is there a way to know if a given process/window is DPI-aware or not, so that I can fix my code with something like this:

Code: Select all

WinGet, Style, Style, ahk_id %window_id%
if ((DPIAware=1) and  (Style & 0x40000))
DllCall("SetThreadDpiAwarenessContext", "ptr", -4, "ptr")
Else
DllCall("SetThreadDpiAwarenessContext", "ptr", -1, "ptr")
[Mod edit: [code][/code] tags added.]

Any help would be appreciated

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get DPI Scaling Awareness level?  Topic is solved

Post by swagfag » 31 Mar 2023, 04:21

dllcall this https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getprocessdpiawareness (and whatever other additional functions it requires, OpenProcess/CloseHandle)

Flowgun
Posts: 75
Joined: 25 Aug 2022, 09:42

Re: Get DPI Scaling Awareness level?

Post by Flowgun » 09 May 2023, 02:30

swagfag wrote:
31 Mar 2023, 04:21
dllcall this https://learn.microsoft.com/en-us/windows/win32/api/shellscalingapi/nf-shellscalingapi-getprocessdpiawareness (and whatever other additional functions it requires, OpenProcess/CloseHandle)
Sorry, I missed the reply. This function is what I was looking for. I also had to calculate the DPI for each screen and multiply/divide by its factor depending on the DPI awareness level to get my script to behave the way I wanted to. It was overly complex for what I thought would be a simple task.

Post Reply

Return to “Ask for Help (v1)”