Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Mahendrakumar
Posts: 20
Joined: 02 Aug 2017, 06:33

Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

04 Aug 2017, 04:39

I have TreeView (TreeViewWndClass1) where i have selected one item using Keyboard keys (up n down) and at there i need right click to open context menu. I don't want to use mouse to get coordinates. Can anybody help me out ? problem is that Appskey doesn't work and no other shortcut are there. only way i found is to get coordinates and use MouseClick Right {x} {y}
User avatar
jeeswg
Posts: 5939
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

05 Aug 2017, 01:12

AccViewer appears to be able to do this for standard treeview controls created in AHK GUIs. So it might work for your control:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Mahendrakumar
Posts: 20
Joined: 02 Aug 2017, 06:33

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

05 Aug 2017, 04:52

Vh_ wrote:ControlGetPos command.

i tried but ControlGetPos doesn't get coordinates of selected text from TreeView. if you have example , could you please show me
Vh_
Posts: 190
Joined: 17 Mar 2017, 22:06

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

05 Aug 2017, 12:27

You may be able to use the following command.

Control, TabLeft, 1, TreeView, WinTitle
Vh_
Posts: 190
Joined: 17 Mar 2017, 22:06

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

05 Aug 2017, 12:28

you could also try the tree view with ControlGetPos, and then when you click X and Y, you do Click X+25, Y.
Mahendrakumar
Posts: 20
Joined: 02 Aug 2017, 06:33

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

06 Aug 2017, 06:49

Vh_ wrote:You may be able to use the following command.

Control, TabLeft, 1, TreeView, WinTitle
what does this script do ?
Mahendrakumar
Posts: 20
Joined: 02 Aug 2017, 06:33

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

06 Aug 2017, 06:57

jeeswg wrote:AccViewer appears to be able to do this for standard treeview controls created in AHK GUIs. So it might work for your control:
Acc library (MSAA) and AccViewer download links - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=26201
What shall i achieve by using this script ?
User avatar
jeeswg
Posts: 5939
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

06 Aug 2017, 07:47

Try it.
Spoiler
Some example code:

Code: Select all

q:: ;get item coordinates/text from a treeview control
ControlGet, hCtl, Hwnd,, SysTreeView321, A
vOutput := ""
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)

Loop, % oAcc.accChildCount
{
	oRect := Acc_Location(oAcc, A_Index)
	vOutput .= oRect.x " " oRect.y " " oRect.w " " oRect.h "`t" oAcc.AccName(A_Index) "`r`n"
}
oAcc := oRect := ""
Clipboard := vOutput
MsgBox, % vOutput
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Mahendrakumar
Posts: 20
Joined: 02 Aug 2017, 06:33

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?  Topic is solved

07 Aug 2017, 13:55

jeeswg wrote:Try it.
Spoiler
Some example code:

Code: Select all

q:: ;get item coordinates/text from a treeview control
ControlGet, hCtl, Hwnd,, SysTreeView321, A
vOutput := ""
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)

Loop, % oAcc.accChildCount
{
	oRect := Acc_Location(oAcc, A_Index)
	vOutput .= oRect.x " " oRect.y " " oRect.w " " oRect.h "`t" oAcc.AccName(A_Index) "`r`n"
}
oAcc := oRect := ""
Clipboard := vOutput
MsgBox, % vOutput
return
Thumb Up... thanks a bunch.. this coordinates helped me a lot.
drizzt
Posts: 26
Joined: 20 Apr 2018, 20:44

Re: Is it possible to get coordinates of selected item in TreeView (TreeViewWndClass1) control ?

04 May 2018, 19:21

jeeswg wrote:Try it.


Some example code:

Code: Select all

q:: ;get item coordinates/text from a treeview control
ControlGet, hCtl, Hwnd,, SysTreeView321, A
vOutput := ""
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)

Loop, % oAcc.accChildCount
{
	oRect := Acc_Location(oAcc, A_Index)
	vOutput .= oRect.x " " oRect.y " " oRect.w " " oRect.h "`t" oAcc.AccName(A_Index) "`r`n"
}
oAcc := oRect := ""
Clipboard := vOutput
MsgBox, % vOutput
return
I dont understand

I am trying to run this on the followin treeview but it doesnt display anything

Code: Select all

Gui, Add, TreeView
P1 := TV_Add("First parent")
P1C1 := TV_Add("Parent 1's first child", P1)  ; Specify P1 to be this item's parent.
P2 := TV_Add("Second parent")
P2C1 := TV_Add("Parent 2's first child", P2)
P2C2 := TV_Add("Parent 2's second child", P2)
P2C2C1 := TV_Add("Child 2's first child", P2C2)

Gui, Show  ; Show the window and its TreeView.
return

GuiClose:  ; Exit the script when the user closes the TreeView's GUI window.
ExitApp

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], ktbjx, Trej and 182 guests