Jump to content

Treeview Expand and Collapse


eltorro
 Share

Recommended Posts

How would one capture the $TVN_EXPANDING ,$TVN_ITEMEXPANDED treeview events???

Steve

Edited by eltorro
Link to comment
Share on other sites

Normally with GUIRegisterMsg() and WM_NOTIFY but there is still a bug/problem at the moment that I have to fix first.

I'm still working on it right now.

Edited by Holger
Link to comment
Share on other sites

Ok, I'll wait.

If got as far as coding a test script but is crashes the first time I click an item (not always the first time but usually).

My ultimate goal is to be to dynamically load the tree with more data as nodes are clicked so as to bypass loading an entire tree on startup.

Link to comment
Share on other sites

  • 6 months later...

It should be.

Hi I tried the following code...

#include <GuiTreeView.au3>

Global Const $WM_COMMAND    = 0x0111
Global Const $LBN_SELCHANGE    = 1
Global Const $LBN_DBLCLK    = 2



Global Const $WS_EX_CLIENTEDGE          = 0x00000200

Dim $h_GUI, $Msg, $treeview
Dim $h_root1, $h_root2, $h_root3
Dim $n_btn_insert
Dim $Drives
Dim $n
Dim $tvd[1]
$tvd[0]=0


$h_GUI = GUICreate("TreeView UDF Sample", 220, 250)

$treeview = GUICtrlCreateTreeView(10, 10, 200, 200, -1, $WS_EX_CLIENTEDGE)
GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND")

$Drives=DriveGetDrive("FIXED")

for $n=1 to $Drives[0]
    redim $tvd[ubound($tvd) +1]
    $tvd[0] = $tvd[0]+1
    $tvd[$n]= _GUICtrlTreeViewInsertItem($treeview, $Drives[$n])
next 


for $n=1 to $Drives[0]
    _GetDirlist($Drives[$n],$tvd[$n])
next



Func _GetDirList($DIR, $roothnd)
   Dim $N_DIRNAMES[200000] ; max number of directories that can be scanned
   Local $N_DIRCOUNT = 0
   Local $N_FILE
   Local $N_SEARCH
   Local $N_TFILE

   Local $T_FILENAMES
   Local $T_FILECOUNT
   Local $T_DIRCOUNT = 1
   
   
   ; remove the end \ If specified
   If StringRight($DIR,1) = "\" Then $DIR = StringTrimRight($DIR,1)
   $N_DIRNAMES[$T_DIRCOUNT] = $DIR
   ; Exit if base dir doesn't exists
   If Not FileExists($DIR) Then Return 0


      $N_DIRCOUNT = $N_DIRCOUNT + 1
      ; find all subdirs in this directory and save them in a array
      $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\*.*") 
      While 1
         $N_FILE = FileFindNextFile($N_SEARCH)
         If @error Then ExitLoop
         ; skip these references
         If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop
         $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE
         ; if Directory than add to the list of directories to be processed
         If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then
            $T_DIRCOUNT = $T_DIRCOUNT + 1
            _GUICtrlTreeViewInsertItem($treeview, $N_FILE, $roothnd)
         EndIf
      Wend
      FileClose($N_SEARCH)

EndFunc 


$n_btn_insert   = GUICtrlCreateButton("Exit", 10, 220, 200, 20)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $n_btn_insert
            exit
    EndSwitch
WEnd



Func MY_WM_COMMAND($hWnd, $Msg, $wParam, $lParam)
    $nNotifyCode    = BitShift($wParam, 16)
    $nID            = BitAnd($wParam, 0x0000FFFF)
    $hCtrl          = $lParam
    If $nID = $treeview Then
        Switch $nNotifyCode                    
            Case $LBN_DBLCLK
                msgbox (0,"Info", "dblclk")   ; should popup whn dblclk
                Return 0
        EndSwitch
    EndIf
EndFunc

works fine with a listview but not with tree view

Greetings mozart90

Link to comment
Share on other sites

#include <GuiTreeView.au3>

Global Const $WM_NOTIFY = 0x004E
Global Const $DebugIt = 1

; TreeView Events
Global Const $NM_FIRST = 0
Global Const $NM_LAST = (-99)
Global Const $NM_CLICK = ($NM_FIRST - 2)
Global Const $NM_DBLCLK = ($NM_FIRST - 3)
Global Const $NM_RETURN = ($NM_FIRST - 4)
Global Const $NM_RCLICK = ($NM_FIRST - 5)
Global Const $NM_RDBLCLK = ($NM_FIRST - 6)
Global Const $NM_SETFOCUS = ($NM_FIRST - 7)
Global Const $NM_KILLFOCUS = ($NM_FIRST - 8)
Global Const $NM_CUSTOMDRAW = ($NM_FIRST - 12)
Global Const $NM_SETCURSOR = ($NM_FIRST - 17)

Global Const $TVN_FIRST = -400
Global Const $TVN_LAST = -499
Global Const $TVN_SELCHANGINGA = ($TVN_FIRST - 1)
Global Const $TVN_SELCHANGINGW = ($TVN_FIRST - 50)
Global Const $TVN_SELCHANGEDA = ($TVN_FIRST - 2)
Global Const $TVN_SELCHANGEDW = ($TVN_FIRST - 51)
Global Const $TVN_GETDISPINFOA = ($TVN_FIRST - 3)
Global Const $TVN_GETDISPINFOW = ($TVN_FIRST - 52)
Global Const $TVN_SETDISPINFOA = ($TVN_FIRST - 4)
Global Const $TVN_SETDISPINFOW = ($TVN_FIRST - 53)
Global Const $TVN_ITEMEXPANDINGA = ($TVN_FIRST - 5)
Global Const $TVN_ITEMEXPANDINGW = ($TVN_FIRST - 54)
Global Const $TVN_ITEMEXPANDEDA = ($TVN_FIRST - 6)
Global Const $TVN_ITEMEXPANDEDW = ($TVN_FIRST - 55)
Global Const $TVN_BEGINDRAGA = ($TVN_FIRST - 7)
Global Const $TVN_BEGINDRAGW = ($TVN_FIRST - 56)
Global Const $TVN_BEGINRDRAGA = ($TVN_FIRST - 8)
Global Const $TVN_BEGINRDRAGW = ($TVN_FIRST - 57)
Global Const $TVN_DELETEITEMA = ($TVN_FIRST - 9)
Global Const $TVN_DELETEITEMW = ($TVN_FIRST - 58)
Global Const $TVN_BEGINLABELEDITA = ($TVN_FIRST - 10)
Global Const $TVN_BEGINLABELEDITW = ($TVN_FIRST - 59)
Global Const $TVN_ENDLABELEDITA = ($TVN_FIRST - 11)
Global Const $TVN_ENDLABELEDITW = ($TVN_FIRST - 60)
Global Const $TVN_KEYDOWN = ($TVN_FIRST - 12)
Global Const $TVN_GETINFOTIPA = ($TVN_FIRST - 13)
Global Const $TVN_GETINFOTIPW = ($TVN_FIRST - 14)
Global Const $TVN_SINGLEEXPAND = ($TVN_FIRST - 15)



Global Const $WS_EX_CLIENTEDGE = 0x00000200

Dim $h_GUI, $Msg, $treeview
Dim $h_root1, $h_root2, $h_root3
Dim $n_btn_insert
Dim $Drives
Dim $n
Dim $tvd[1]
$tvd[0] = 0


$h_GUI = GUICreate("TreeView UDF Sample", 220, 250)

$treeview = GUICtrlCreateTreeView(10, 10, 200, 200, -1, $WS_EX_CLIENTEDGE)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events")

$Drives = DriveGetDrive("FIXED")

For $n = 1 To $Drives[0]
    ReDim $tvd[UBound($tvd) + 1]
    $tvd[0] = $tvd[0] + 1
    $tvd[$n] = _GUICtrlTreeViewInsertItem($treeview, $Drives[$n])
Next


For $n = 1 To $Drives[0]
    _GetDirList($Drives[$n], $tvd[$n])
Next



Func _GetDirList($DIR, $roothnd)
    Dim $N_DIRNAMES[200000] ; max number of directories that can be scanned
    Local $N_DIRCOUNT = 0
    Local $N_FILE
    Local $N_SEARCH
    Local $N_TFILE

    Local $T_FILENAMES
    Local $T_FILECOUNT
    Local $T_DIRCOUNT = 1


    ; remove the end \ If specified
    If StringRight($DIR, 1) = "\" Then $DIR = StringTrimRight($DIR, 1)
    $N_DIRNAMES[$T_DIRCOUNT] = $DIR
    ; Exit if base dir doesn't exists
    If Not FileExists($DIR) Then Return 0


    $N_DIRCOUNT = $N_DIRCOUNT + 1
    ; find all subdirs in this directory and save them in a array
    $N_SEARCH = FileFindFirstFile($N_DIRNAMES[$N_DIRCOUNT] & "\*.*")
    While 1
        $N_FILE = FileFindNextFile($N_SEARCH)
        If @error Then ExitLoop
        ; skip these references
        If $N_FILE = "." Or $N_FILE = ".." Then ContinueLoop
        $N_TFILE = $N_DIRNAMES[$N_DIRCOUNT] & "\" & $N_FILE
        ; if Directory than add to the list of directories to be processed
        If StringInStr(FileGetAttrib($N_TFILE), "D") > 0 Then
            $T_DIRCOUNT = $T_DIRCOUNT + 1
            _GUICtrlTreeViewInsertItem($treeview, $N_FILE, $roothnd)
        EndIf
    WEnd
    FileClose($N_SEARCH)

EndFunc   ;==>_GetDirList


$n_btn_insert = GUICtrlCreateButton("Exit", 10, 220, 200, 20)

GUISetState()

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $n_btn_insert
            Exit
    EndSwitch
WEnd

Func TreeView_Click()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then    _DebugPrint ("TreeView_Click")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>TreeView_Click

Func TreeView_DoubleClick()
    ;----------------------------------------------------------------------------------------------
    If $DebugIt Then    _DebugPrint ("TreeView_DoubleClick")
    ;----------------------------------------------------------------------------------------------
EndFunc   ;==>TreeView_DoubleClick
;
; WM_NOTIFY event handler
Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam)
    #forceref $hWndGUI, $MsgID, $wParam
    Local $tagNMHDR, $event
    $tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code)
    If @error Then Return
    $event = DllStructGetData($tagNMHDR, 3)
    Select
        Case $wParam = $treeview
            Switch $event
                Case $NM_CLICK
                    TreeView_Click()
                Case $NM_CUSTOMDRAW
                Case $NM_DBLCLK
                    TreeView_DoubleClick()
                Case $NM_KILLFOCUS
                Case $NM_RCLICK
                Case $NM_RDBLCLK
                Case $NM_RETURN
                Case $NM_SETCURSOR
                Case $NM_SETFOCUS
                Case $TVN_SELCHANGINGA, $TVN_SELCHANGINGW
                Case $TVN_SELCHANGEDA, $TVN_SELCHANGEDW
                Case $TVN_GETDISPINFOA, $TVN_GETDISPINFOW
                Case $TVN_SETDISPINFOA, $TVN_SETDISPINFOW
                Case $TVN_ITEMEXPANDINGA, $TVN_ITEMEXPANDINGW
                    _DebugPrint("Item Expanding")
                Case $TVN_ITEMEXPANDEDA, $TVN_ITEMEXPANDEDW
                    _DebugPrint("Item Expanded")
                Case $TVN_BEGINDRAGA, $TVN_BEGINDRAGW
                Case $TVN_BEGINRDRAGA, $TVN_BEGINRDRAGW
                Case $TVN_DELETEITEMA, $TVN_DELETEITEMW
                Case $TVN_BEGINLABELEDITA, $TVN_BEGINLABELEDITW
                Case $TVN_ENDLABELEDITA, $TVN_ENDLABELEDITW
                Case $TVN_KEYDOWN
                Case $TVN_GETINFOTIPA, $TVN_GETINFOTIPW
                Case $TVN_SINGLEEXPAND
            EndSwitch
    EndSelect
    $tagNMHDR = 0
    $event = 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

Func _DebugPrint($s_text)
    $s_text = StringReplace($s_text, @LF, @LF & "-->")
    ConsoleWrite("!===========================================================" & @LF & _
            "+===========================================================" & @LF & _
            "-->" & $s_text & @LF & _
            "+===========================================================" & @LF)
EndFunc   ;==>_DebugPrint

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...