wahoyaho Posted November 23, 2007 Posted November 23, 2007 (edited) How can I detect when the buttons are click using OnEvent? Edited November 23, 2007 by wahoyaho
wahoyaho Posted November 23, 2007 Author Posted November 23, 2007 By buttons I mean the + and - buttons when TVS_HASBUTTONS is on Or, the checkboxes?
smashly Posted November 25, 2007 Posted November 25, 2007 (edited) hi, run this example from Scite 11/15/07 using current AutoIt v3.2.10.0. The console output in scite will tell what has been clicked..expandcollapse popup#include<GuiConstantsEx.au3> #Include<GuiTreeView.au3> #Include<WinAPI.au3> Opt("GUIOnEventMode", 1) $Gui = GUICreate("Treeview", 300, 375) $TreeView = GUICtrlCreateTreeView(5, 30, 290, 310, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_CHECKBOXES)) For $i = 1 To 5 GUICtrlCreateTreeViewItem("Item " & $i, $TreeView) GUICtrlSetOnEvent(-1, "Event") GuiCtrlSetImage(-1, "shell32.dll", -42, 4) GuiCtrlSetImage(-1, "shell32.dll", -42, 2) GUICtrlCreateTreeViewItem("Sub Item " & $i, -1) GUICtrlSetOnEvent(-1, "Event") GuiCtrlSetImage(-1, "shell32.dll", -85, 4) GuiCtrlSetImage(-1, "shell32.dll", -85, 2) Next GUISetOnEvent($GUI_EVENT_CLOSE, "Close") GUISetState(@SW_SHOW, $Gui) GUIRegisterMsg($WM_NOTIFY, "MY_WM_NOTIFY") While 1 Sleep(100) WEnd Func Event() ConsoleWrite("Event: Selected Treeview Text: " & GUICtrlRead(GUICtrlRead($TreeView), 1) & @LF) EndFunc Func Close() Exit EndFunc Func MY_WM_NOTIFY($hWnd, $nMsg, $wParam, $lParam) Local $nID = BitAnd($wParam, 0x0000FFFF) Local $stNmhdr = DllStructCreate("dword;int;int", $lParam) Local $hWndFrom = DllStructGetData($stNmhdr, 1) Local $nNotifyCode = DllStructGetData($stNmhdr, 3) If Not ($nNotifyCode = $NM_CLICK Or $nNotifyCode = $TVN_KEYDOWN) Then Return $GUI_RUNDEFMSG Local $tagPOINT = _WinAPI_GetMousePos(True, $hWndFrom) Switch _GUICtrlTreeView_HitTest($nID, DllStructGetData($tagPOINT, 1), DllStructGetData($tagPOINT, 2)) Case 2 ConsoleWrite("--------------------------------" & @LF) ConsoleWrite("MY_WM_NOTIFY: Treeview Icon clicked" & @LF) Case 4 ConsoleWrite("--------------------------------" & @LF) ConsoleWrite("MY_WM_NOTIFY: Treeview Text clicked" & @LF) Case 16 ConsoleWrite("--------------------------------" & @LF) ConsoleWrite("MY_WM_NOTIFY: Treeview Button clicked" & @LF) Case 64 ConsoleWrite("--------------------------------" & @LF) ConsoleWrite("MY_WM_NOTIFY: Treeview Checkbox clicked" & @LF) EndSwitch Return $GUI_RUNDEFMSG EndFuncCheers Edited November 25, 2007 by smashly
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now