Use Acc_Location to get taskbar item position and width

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Use Acc_Location to get taskbar item position and width

Post by mikeyww » 30 Oct 2021, 23:51

I can use Acc to find the taskbar items' x-position and width, but the numbers do not match what I see in Window Spy. Why?

Code: Select all

#SingleInstance Force
#Include d:\utils\acc\Acc.ahk
CoordMode, Mouse
ControlGet, hWnd, Hwnd,, MSTaskListWClass1, ahk_class Shell_TrayWnd
For each, child in Acc_Children(oAcc := Acc_Get("Object", "tool bar", 0, "ahk_id " hWnd)) {
 name := oAcc.accName(child), oRect := Acc_Location(oAcc, child)
 If !oRect.x || name = ""
  Continue
 MouseMove, oRect.x, oRect.y
 MsgBox, 262144,, % name ": " oRect.x " " oRect.x + oRect.w
}
Operating system : Microsoft Windows 10 Pro
OS version : 10.0.19043
CPU : Intel64 Family 6 Model 140 Stepping 1
OS bitness : 64
CPU bitness : 64
Display : Citrix Indirect Display Adapter
Display width : 1920
Display height : 1080
DPI : 144
AHK : 1.1.33.10

In this screenshot, Acc shows x = 270, but when the cursor is placed at x = 270, it is not the item's x-position.

sshot-1_cr.png
Screenshot showing cursor position, Acc x-value, and Window Spy
sshot-1_cr.png (158.6 KiB) Viewed 951 times

It seems that even if the returned coordinates are relative to the taskbar itself or even the control, the numbers are wrong. I do notice that the taskbar items seem to elongate very briefly, so could the findings be related to how Windows compresses the button widths? Is there a way to resolve the problem and get the taskbar item dimensions shown on screen?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Use Acc_Location to get taskbar item position and width

Post by mikeyww » 31 Oct 2021, 09:31

Thanks. I tried some scaling but will try again.
doubledave22
Posts: 343
Joined: 08 Jun 2019, 17:36

Re: Use Acc_Location to get taskbar item position and width

Post by doubledave22 » 31 Oct 2021, 10:13

I run into this fairly often as well and would love to know a good way to solve it. AccessibleObjectFromPoint seems to fail on high dpi which is a bummer. It looks like it could be solved however by converting from physical to logical or vice versa.

I tried to find examples of PhysicalToLogicalPoint https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-physicaltologicalpoint on the forums but couldn't. It doesn't look overly hard however I am not good at translating c++ to ahk. Anyone able to do this real fast for us?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Use Acc_Location to get taskbar item position and width

Post by mikeyww » 31 Oct 2021, 18:10

In my script, multiplying the x-coordinate by A_ScreenDPI/96 was not the solution. I am still thinking that the problem relates to the button squeezing that Windows does on the taskbar. I tested that by having a taskbar with only a few items. It looks like it mostly worked, though there seems to be an x-offset of some kind after the first item. Nonetheless, I still have no solution in my situation with many taskbar items.
malcev
Posts: 1769
Joined: 12 Aug 2014, 12:37

Re: Use Acc_Location to get taskbar item position and width

Post by malcev » 31 Oct 2021, 18:56

I recommend You get accexplorer32, examine tree of objects and compare objects location with mouse coordinates.
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: Use Acc_Location to get taskbar item position and width

Post by mikeyww » 31 Oct 2021, 19:21

OK. Thanks, malcev.
Post Reply

Return to “Ask for Help (v1)”