Sign in to follow this  
Followers 0
Makaule

[SOLVED] _GUICtrlTreeView_ if clicked (On Event)

5 posts in this topic

#1 ·  Posted (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
WEnd

I 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 by Makaule

Share this post


Link to post
Share on other sites



Uhhmm.. Maybe this help you..

#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]

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hmm.. I don't think you want this quite long codes.. But you may try..

#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 by ichigo325

[size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size]

Share this post


Link to post
Share on other sites

That one i have seen in Help file. Well i think, i will mark it as solved.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0