Makaule Posted July 12, 2010 Share Posted July 12, 2010 (edited) Hello, All, again.I am just curious, maybe as always, i just missed something, is it possible to tell what should be done if one or other item is selected in treeview? I want to enable button if Child item selected and disable it if Parent item selected in the treeview.Here is my code:#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 633, 454, 192, 114) $Style = BitOR($TVS_NOHSCROLL, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP) $TreeView1 = _GUICtrlTreeView_Create($Form1, 40, 24, 185, 185, $Style, $WS_EX_CLIENTEDGE) $mListDay = _GUICtrlTreeView_Add($TreeView1, 0, "Daily") $DayChild1 = _GUICtrlTreeView_AddChild($TreeView1, $mListDay, "1. ") $DayChild2 = _GUICtrlTreeView_AddChild($TreeView1, $mListDay, "2. ") $mListMonth = _GUICtrlTreeView_Add($TreeView1, 0, "Monthly") $MonthChild1 = _GUICtrlTreeView_AddChild($TreeView1, $mListMonth, "11. ") $MonthChild2 = _GUICtrlTreeView_AddChild($TreeView1, $mListMonth, "22. ") $Button1 = GUICtrlCreateButton("Button1", 40, 232, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Button2", 152, 232, 75, 25, $WS_GROUP) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEndI know that it's possible to do with GUICtrlCreateTreeView(), but problem is that i dont want to rebuild GUI and I also need some specific functions like TreeView sorting. Edited July 13, 2010 by Makaule Link to comment Share on other sites More sharing options...
ichigo325 Posted July 12, 2010 Share Posted July 12, 2010 Uhhmm.. Maybe this help you.. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> $Form1 = GUICreate("Form1", 633, 454, 192, 114) $Style = BitOR($TVS_NOHSCROLL, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP) $TreeView1 = _GUICtrlTreeView_Create($Form1, 40, 24, 185, 185, $Style, $WS_EX_CLIENTEDGE) $mListDay = _GUICtrlTreeView_Add($TreeView1, 0, "Daily") $DayChild1 = _GUICtrlTreeView_AddChild($TreeView1, $mListDay, "1. ") $DayChild2 = _GUICtrlTreeView_AddChild($TreeView1, $mListDay, "2. ") $mListMonth = _GUICtrlTreeView_Add($TreeView1, 0, "Monthly") $MonthChild1 = _GUICtrlTreeView_AddChild($TreeView1, $mListMonth, "11. ") $MonthChild2 = _GUICtrlTreeView_AddChild($TreeView1, $mListMonth, "22. ") $Button1 = GUICtrlCreateButton("Button1", 40, 232, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Button2", 152, 232, 75, 25, $WS_GROUP) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) ;~ While 1 ;*If style loops ;~ $nMsg = GUIGetMsg() ;~ If $nMsg = $GUI_EVENT_PRIMARYDOWN Then ;~ $hSelected = _GUICtrlTreeView_GetSelection($TreeView1) ;~ If $hSelected = $DayChild1 Then GUICtrlSetState($Button2,64) ;~ If $hSelected = $mListDay Then GUICtrlSetState($Button2,128) ;~ EndIf ;~ If $nMsg = -3 Then ;~ Exit ;~ EndIf ;~ WEnd While 1 ;*Switch/case style loop $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_PRIMARYDOWN $hSelected = _GUICtrlTreeView_GetSelection($TreeView1) If $hSelected = $DayChild1 Then GUICtrlSetState($Button2, 64) If $hSelected = $mListDay Then GUICtrlSetState($Button2, 128) EndSwitch WEnd [size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size] Link to comment Share on other sites More sharing options...
Makaule Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks for example. As i like OnEventMode more then this method, i have used GuiSetOnEvent($GUI_EVENT_PRIMARYDOWN, "_TreeViewSelection"), but maybe there is better way? At the moment it checks if mouse is pressed in GUI, so each time when i press on GUI, it make check, maybe there is any method, which could check only if i press on TreeView window? Link to comment Share on other sites More sharing options...
ichigo325 Posted July 12, 2010 Share Posted July 12, 2010 (edited) Hmm.. I don't think you want this quite long codes.. But you may try.. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> Global $TreeView1, $hSelected, $DayChild1, $Button2, $mListDay, $Button2 $Form1 = GUICreate("Form1", 633, 454, 192, 114) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $Style = BitOR($TVS_NOHSCROLL, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP) $TreeView1 = _GUICtrlTreeView_Create($Form1, 40, 24, 185, 185, $Style, $WS_EX_CLIENTEDGE) $mListDay = _GUICtrlTreeView_Add($TreeView1, 0, "Daily") $DayChild1 = _GUICtrlTreeView_AddChild($TreeView1, $mListDay, "1. ") $DayChild2 = _GUICtrlTreeView_AddChild($TreeView1, $mListDay, "2. ") $mListMonth = _GUICtrlTreeView_Add($TreeView1, 0, "Monthly") $MonthChild1 = _GUICtrlTreeView_AddChild($TreeView1, $mListMonth, "11. ") $MonthChild2 = _GUICtrlTreeView_AddChild($TreeView1, $mListMonth, "22. ") $Button1 = GUICtrlCreateButton("Button1", 40, 232, 75, 25, $WS_GROUP) $Button2 = GUICtrlCreateButton("Button2", 152, 232, 75, 25, $WS_GROUP) GUICtrlSetState(-1, $GUI_DISABLE) GUISetState(@SW_SHOW) While 1 ;*If style loops $nMsg = GUIGetMsg() If $nMsg = -3 Then Exit EndIf WEnd Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $TreeView1 If Not IsHWnd($TreeView1) Then $hWndTreeview = GUICtrlGetHandle($TreeView1) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ;~ Return 1 ; nonzero to not allow the default processing $hSelected = _GUICtrlTreeView_GetSelection($TreeView1) If $hSelected = $DayChild1 Then GUICtrlSetState($Button2, 128) If $hSelected = $mListDay Then GUICtrlSetState($Button2, 64) Return 0 ; zero to allow the default processing Case $NM_DBLCLK ; The user has double-clicked the left mouse button within the control _DebugPrint("$NM_DBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ;~ Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing Case $NM_RCLICK ; The user has clicked the right mouse button within the control _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ;~ Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing Case $NM_RDBLCLK ; The user has clicked the right mouse button within the control _DebugPrint("$NM_RDBLCLK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ;~ Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing Case $NM_SETFOCUS ; control has received the input focus _DebugPrint("$NM_SETFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value Case $NM_KILLFOCUS ; control has lost the input focus _DebugPrint("$NM_KILLFOCUS" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) ; No return value EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint Edited July 12, 2010 by ichigo325 [size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size] Link to comment Share on other sites More sharing options...
Makaule Posted July 13, 2010 Author Share Posted July 13, 2010 That one i have seen in Help file. Well i think, i will mark it as solved. 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