Furek86 Posted December 7, 2012 Share Posted December 7, 2012 hey guys, I am having an issue with my treeview control. I want to get the text of a selected item, but only when I click on THE item, not when I click on the expand symbol (+). Could anyone help? Or if it was already raised and resolved, point me to the right thread? $treeViewOUs = GUICtrlCreateTreeView(16, 232, 209, 345, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Global $hTreeView = GUICtrlGetHandle($treeViewOUs) Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam) Local $tNMHDR, $IdFrom, $iCode $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $IdFrom = DllStructGetData($tNMHDR, "IdFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTreeView Switch $iCode Case $NM_CLICK ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView,_GUICtrlTreeView_GetSelection($hTreeView)) & @CRLF) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 7, 2012 Moderators Share Posted December 7, 2012 Furek86,I would do it like this - the "click" comes first and arms an Adlib function. If if it is followed almost immediately (withint 5 ms on my machine) by an "expand/contract" message we cancel the Adlib function: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GuiTreeView.au3> $fClicked = False $hGUI = GUICreate("Test", 500, 500) $treeViewOUs = GUICtrlCreateTreeView(16, 32, 209, 345, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) Global $hTreeView = GUICtrlGetHandle($treeViewOUs) $generalitem = GUICtrlCreateTreeViewItem("General", $treeViewOUs) $displayitem = GUICtrlCreateTreeViewItem("Display", $treeViewOUs) $aboutitem = GUICtrlCreateTreeViewItem("About", $generalitem) $compitem = GUICtrlCreateTreeViewItem("Computer", $generalitem) GUICtrlCreateTreeViewItem("User", $generalitem) GUICtrlCreateTreeViewItem("Resolution", $displayitem) GUICtrlCreateTreeViewItem("Other", $displayitem) $cClk_Dummy = GUICtrlCreateDummy() GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _Read() ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView, _GUICtrlTreeView_GetSelection($hTreeView)) & " <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<" & @CRLF) AdlibUnRegister("_Read") EndFunc ;==>_Read Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hTreeView Switch $iCode Case $NM_CLICK AdlibRegister("_Read", 20) ConsoleWrite("Registered" & @CRLF) Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA AdlibUnRegister("_Read") ConsoleWrite("Unregistered" & @CRLF) EndSwitch EndSwitch EndFunc ;==>_WM_NOTIFYI have left the ConsoleWrite lines in so you can see what is happening. M23 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...
Furek86 Posted December 10, 2012 Author Share Posted December 10, 2012 thanks man, seems to be working ok 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