snify Posted August 20, 2009 Share Posted August 20, 2009 (edited) Hey there, I have a simple GUI with a treeview and 4 Parent-Items. Each Parent-Item has 1 Child Item. (just a info) I need a Event (or something like this) When I expand (I click the + button) the treeview, I just want a msgbox with a text, which parentitem were opened. Have someone a simple example code for me? thank you Greetz Snify EDIT: I am using GUIGETMSG() for my GUI Edited August 20, 2009 by snify Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted August 20, 2009 Moderators Share Posted August 20, 2009 (edited) snify, First, welcome to the AutoIt forums. I hope you do mind me pointing out that when you post here it always helps if you have had a go at solving your problem beforehand. Having some code to work on is a great help - and no-one here is too keen to help the "code it for me" brigade. >_< However, as you were not to know that, take a look at this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <GuiTreeView.au3> Global $hTreeView, $fExpanded = 0 Global $ahRoot[5][2] = [[0, 0],[0, 0],[0, 0],[0, 0]] $hGUI = GUICreate("Test", 220, 250) $hTreeView = GUICtrlCreateTreeView(10, 10, 200, 200, -1, $WS_EX_CLIENTEDGE) $ahRoot[1][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem1") _GUICtrlTreeView_InsertItem($hTreeView, "SubItem1", $ahRoot[1][0]) $ahRoot[2][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem2") _GUICtrlTreeView_InsertItem($hTreeView, "SubItem2", $ahRoot[2][0]) $ahRoot[3][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem3") _GUICtrlTreeView_InsertItem($hTreeView, "SubItem3", $ahRoot[3][0]) $ahRoot[4][0] = _GUICtrlTreeView_InsertItem($hTreeView, "RootItem4") _GUICtrlTreeView_InsertItem($hTreeView, "SubItem4", $ahRoot[4][0]) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $iMsg = GUIGetMsg() Select Case $iMsg = $GUI_EVENT_CLOSE Exit Case $fExpanded = 1 ; node closed so reset all nodes to current states For $i = 1 To 4 If _GUICtrlTreeView_GetExpanded($hTreeView, $ahRoot[$i][0]) = True Then $ahRoot[$i][1] = 1 ; set expanded flag Else $ahRoot[$i][1] = 0 ; set closed flag EndIf Next $fExpanded = 0 Case $fExpanded = 2 ; node opened so check which changed For $i = 1 To 4 If _GUICtrlTreeView_GetExpanded($hTreeView, $ahRoot[$i][0]) <> $ahRoot[$i][1] Then $sText = _GUICtrlTreeView_GetText($hTreeView, $ahRoot[$i][0]) EndIf Next MsgBox(0x40000, "+ Clicked", $sText) $fExpanded = 0 EndSelect WEnd Func WM_Notify_Events($hWndGUI, $iMsgID, $wParam, $lParam) #forceref $hWndGUI, $iMsgID Local $tagNMHDR = DllStructCreate("int;int;int;int", $lParam) If @error Then Return Local $iEvent = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $hTreeView Switch $iEvent Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA $fExpanded = DllStructGetData($tagNMHDR, 4) ; 1 = node closed, 2 = node expanded EndSwitch EndSelect $tagNMHDR = 0 Return $GUI_RUNDEFMSG EndFunc ;==>WM_Notify_Events I enjoyed getting that to work - and the rain has now stopped so the gardening calls! M23 Edit: Minor code alteration Edited August 20, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
snify Posted August 20, 2009 Author Share Posted August 20, 2009 Hey, thank you Melba23 It works very fine >_< Keep up your work So long, Snify Link to comment Share on other sites More sharing options...
vvdh Posted October 16, 2013 Share Posted October 16, 2013 Hi, I'm looking for the same; a notification when a treeview item is opened or closed. So the notification should tell which treeview item it is, and whether it has been opened er closed. In my search, I do see options for getting notified that an item within the treeview is opened or closed, but not which items was opened or closed. Melba23 made some nice logic to determine which item it was, by checking on the old and the new state. But much rather using such logic, I would like to use a direct notification from the OS which treeview item was opened/closed. Does anyone know how this can be done? Thanks! vvhd Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 16, 2013 Moderators Share Posted October 16, 2013 vvdh,My coding skills have moved on a bit since then - you need to look for the $TVN_ITEMEXPANDEDW or $TVN_ITEMEXPANDEDA message like this (the example is taken from my ChooseFileFolder UDF):Func _CFF_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam ; Create NMTREEVIEW structure Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _ "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _ "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _ "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _ "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _ "struct;long PointX;long PointY;endstruct", $lParam) Local $hWndFrom = DllStructGetData($tStruct, "hWndFrom") ; The control sending the message - the treeview itself Local $hItem = DllStructGetData($tStruct, "NewhItem") ; The item within the treeview being expanded Local $iCode = DllStructGetData($tStruct, "Code") ; The code used If $hWndFrom = $hCFF_TreeView Then Switch $iCode Case 0xFFFFFFFD ; $NM_DBLCLK ; Fire the dummy control GUICtrlSendToDummy($cCFF_DblClk_Dummy) ; Set flag $fCFF_ActiveTV = True Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA ; Something is being expanded/contracted <<<<<<<<<<<<<<< ; Check that expansion is not ongoing If GUICtrlRead($cCFF_Expand_Dummy) = 0 Then ; Fire the dummy control GUICtrlSendToDummy($cCFF_Expand_Dummy, $hItem) EndIf ; Set flag $fCFF_ActiveTV = True EndSwitch EndIf EndFunc ;==>_CFF_WM_NOTIFY_HandlerPlease ask if you have any questions. M23 mLipok 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
vvdh Posted October 17, 2013 Share Posted October 17, 2013 Thanks a lot M23! That looks promising. I'll look into that. If I run into problems, I'll ask vvdh Link to comment Share on other sites More sharing options...
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