pizzaking Posted September 8, 2008 Posted September 8, 2008 (edited) Hi there, the question is in the topic. There is a way as described in help file for the UDF _GUICtrlTreeView_Create(), but this would blow up my script very much. Is there no easy way to react whenever the selection is changed with a standart MessageLoop and GUIGetMsg() ? Thanks for any response!! Edited September 8, 2008 by pizzaking
rasim Posted September 9, 2008 Posted September 9, 2008 pizzakingExample:#include <GuiConstantsEx.au3> Opt("GuiOnEventMode", 1) $hGUI = GUICreate("Test", 200, 200) GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") $hTreeView = GUICtrlCreateTreeView(10, 10, 180, 180) For $i = 1 To 10 $hChild = GUICtrlCreateTreeViewItem("Item " & $i, $hTreeView) GUICtrlSetOnEvent(-1, "_TreeViewItem_Read") GUICtrlCreateTreeViewItem("Sub Item " & $i, $hChild) GUICtrlSetOnEvent(-1, "_TreeViewItem_Read") Next GUISetState() While 1 Sleep(100) WEnd Func _TreeViewItem_Read() MsgBox(0, "Item Text", GUICtrlRead(@GUI_CtrlId, 1)) EndFunc Func _Exit() Exit EndFunc
zeevid Posted September 10, 2008 Posted September 10, 2008 Hi there, the question is in the topic. There is a way as described in help file for the UDF _GUICtrlTreeView_Create(), but this would blow up my script very much. Is there no easy way to react whenever the selection is changed with a standart MessageLoop and GUIGetMsg() ? Thanks for any response!! If you do not want to use the OnEvent method of GUI control you can do the following... expandcollapse popup#include <GuiTreeView.au3> #include <TreeViewConstants.au3> ;somewhere in the beginning of your program, set $WM_NOTIFY to be available with the following code: ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ;This will monitor the events that occur with your GUI and run a function called WM_Notify_Events. In this ; code you will monitor the events for your TreeViewControl and act on those events that you want to. ; WM_NOTIFY event handler ; Events that start with $NM_ are for ListView controls ; Events that start with $TVN_ are for TreeView controls ; As you can see I am running a function every time the selection in the TreeView changes. You can move your code around ; under the different events for $TVN_ to see what works for you best. ; Another note, I have code (If $Bypass_TreeView_Processing = "True" Then Return) because there are times, like ; when you are loading the TreeView with data Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $h_item $tagNMHDR = DllStructCreate("int;int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) If $Bypass_TreeView_Processing = "True" Then Return Select Case $wParam = $treeDistribution_Lists Select Case $event = $NM_CLICK ; Case $event = $NM_DBLCLK ; Case $event = $TVN_ITEMEXPANDINGA Or $event = $TVN_ITEMEXPANDINGW ; Case $event = $NM_SETFOCUS ; Case $event = $NM_RETURN Or $event = $NM_RCLICK Or $event = $NM_RDBLCLK Or $event = $NM_KILLFOCUS Case $event = $NM_OUTOFMEMORY Or $event = $NM_CUSTOMDRAW Or $event = $NM_HOVER Or $event = $NM_NCHITTEST Or $event = $NM_KEYDOWN Or $event = $NM_RELEASEDCAPTURE Case $event = $NM_SETCURSOR Or $event = $NM_CHAR Or $event = $NM_TOOLTIPSCREATED Case $event = $TVN_ITEMEXPANDEDA ; Case $TVN_SELCHANGEDA Or $TVN_SELCHANGEDW $h_item = GUICtrlSendMsg($treeDistribution_Lists, $TVM_GETNEXTITEM, $TVGN_CARET, 0) If $h_item > 0 Then LoadTreeData() EndIf EndSelect EndSelect $tagNMHDR = 0 $event = 0 $lParam = 0 ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>WM_Notify_Events
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