Doubleclick On Selected Treeview Item Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
NovaRanger
Posts: 68
Joined: 23 Oct 2014, 02:05

Doubleclick On Selected Treeview Item

24 Feb 2018, 04:35

Hello Guys, :D

I have a Non_AHK GUI with a treeview in it.
Inside the treeview, i have to navigate down thrice a branch and select an item, after selecting the item i need to open it so that i can change some values, (this has to be done for like 500 branches) :wtf:

And {Enter} doesn't seem to activate it or do anything in this GUI. :crazy:


I read about something similar in this post
https://autohotkey.com/board/topic/4462 ... ew32-item/
and
something really close in this post, this one gives me the coordinates of all the 500 items in the tree. (Would be nice if i could just have the selected one alone)
https://autohotkey.com/boards/viewtopic.php?t=35455

(Code under Spoiler)
Spoiler
Basically what i need is to doubleclick on the selected item in the treeview or else i could even settle for getting the coordinates of the selected item (i would mouseclick from here)
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Doubleclick On Selected Treeview Item  Topic is solved

26 Feb 2018, 02:47

This worked for me to invoke the focused treeview item.

Code: Select all

;[Acc functions]
;Acc library (MSAA) and AccViewer download links - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=26201

q:: ;treeview - invoke focused item
ControlGet, hCtl, Hwnd,, SysTreeView321, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
;MsgBox, % oAcc.accChildCount
Loop, % oAcc.accChildCount
{
	;STATE_SYSTEM_FOCUSED := 0x4
	;if (oAcc.accState(A_Index) & 0x4)
	;	MsgBox, % oAcc.accName(A_Index)
	if (oAcc.accState(A_Index) & 0x4)
		try oAcc.accDoDefaultAction(A_Index)
}
oAcc := ""
return
[EDIT:] Here's a variant that uses the Click command to click the items, however I couldn't get ControlClick to work, and it seems that neither did HotKeyIt, in the example you posted.

Code: Select all

w:: ;treeview - double-click item
WinGet, hWnd, ID, A
ControlGet, hCtl, Hwnd,, SysTreeView321, A
oAcc := Acc_Get("Object", "4", 0, "ahk_id " hCtl)
;MsgBox, % oAcc.accChildCount
Loop, % oAcc.accChildCount
{
	;STATE_SYSTEM_FOCUSED := 0x4
	;if (oAcc.accState(A_Index) & 0x4)
	;	MsgBox, % oAcc.accName(A_Index)
	if (oAcc.accState(A_Index) & 0x4)
	{
		oRect := Acc_Location(oAcc, A_Index)
		CoordMode, Mouse, Screen
		vMouseX := oRect.x + oRect.w/2
		vMouseY := oRect.y + oRect.h/2
		MouseMove, % vMouseX, % vMouseY
		Click, 2

		;attempt to use ControlClick not working
		WinGetPos, vWinX, vWinY,,, % "ahk_id " hWnd
		vMouseX -= vWinX, vMouseY -= vWinY
		;MsgBox, % "X" Round(vMouseX) " Y" Round(vMouseY)
		;ControlClick, % "X" Round(vMouseX) " Y" Round(vMouseY), % "ahk_id " hWnd,,, 2
		;ControlClick, % "X" Round(vMouseX) " Y" Round(vMouseY), % "ahk_id " hWnd,,, 2, NA
		;ControlClick, % "X" Round(vMouseX) " Y" Round(vMouseY), % "ahk_id " hWnd
		;Sleep, 300
		;ControlClick, % "X" Round(vMouseX) " Y" Round(vMouseY), % "ahk_id " hWnd
	}
}
oAcc := ""
return
Last edited by jeeswg on 26 Feb 2018, 03:34, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Doubleclick On Selected Treeview Item

26 Feb 2018, 02:59

- I was trying to do this via more traditional methods, but it didn't work, in case someone can point out what's going on here. If I could get this to work on an internal control, I would then try and get this working on an external control using remote buffers.

Code: Select all

q:: ;treeview GUI
Gui, New, +HwndhGui, MyWinTitle
Gui, Add, TreeView, gMyTVSub
vTV1 := TV_Add("TV 1", "", "Select")
vTV2 := TV_Add("TV 2", vTV1)
vTV3 := TV_Add("TV 3", vTV2)
vTV4 := TV_Add("TV 4", vTV1)
vTV5 := TV_Add("TV 5")
Gui, Show, w300 h300
return

MyTVSub:
ToolTip, % A_GuiEvent
return

;Tree View Notifications (Windows)
;https://msdn.microsoft.com/en-us/library/windows/desktop/ff486107(v=vs.85).aspx

w:: ;treeview - attempt to double-click focused item
ControlGet, hCtl, Hwnd,, SysTreeView321, A
;TVGN_CARET := 0x9
;hItem := SendMessage(0x110A, 0x9, 0,, "ahk_id " hCtl) ;TVM_GETNEXTITEM := 0x110A
;GWL_ID := -12
vCtlID := DllCall("GetWindowLong" (A_PtrSize=8?"Ptr":""), Ptr,hCtl, Int,-12, Ptr)
VarSetCapacity(NMHDR, A_PtrSize=8?24:12, 0)
NumPut(hCtl, &NMHDR, 0, "Ptr") ;hwndFrom
NumPut(vCtlID, &NMHDR, A_PtrSize=8?8:4, "UPtr") ;idFrom
;NM_DBLCLK := -3 ;0xFFFFFFFD
NumPut(-3, &NMHDR, A_PtrSize=8?16:8, "UInt") ;code
;NM_CLICK := -2 ;0xFFFFFFFE
;NumPut(-2, &NMHDR, A_PtrSize=8?16:8, "UInt") ;code
hWndParent := DllCall("user32\GetAncestor", Ptr,hCtl, UInt,1, Ptr) ;GA_PARENT := 1
;MsgBox, % DllCall("user32\GetDoubleClickTime", UInt) ;500
PostMessage, 0x4E,, % &NMHDR,, % "ahk_id " hWndParent ;WM_NOTIFY := 0x4E
;Sleep, 400
;PostMessage, 0x4E,, % &NMHDR,, % "ahk_id " hWndParent ;WM_NOTIFY := 0x4E
return
- Anyhow, it would be probably better to use ControlClick. @kArThIcK hAcKeR 333: Were you not able to do this via ControlClick (or the 'WM_' messages as in HotKeyIt's example that you posted a link to), once you had the coordinates?
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
NovaRanger
Posts: 68
Joined: 23 Oct 2014, 02:05

Re: Doubleclick On Selected Treeview Item

27 Feb 2018, 00:01

Spoiler
Thanks for the reply "jeeswg".
The second code seems to find the co-ordinates correctly.
I can invoke a normal click itself now (something is better than nothing :P).

As for the code in the third post, (controlclick type).. it didnot work (even in the AHK-GUI).

Thanks :)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: doodles333, iamMG, Theda and 173 guests