Jump to content

Stuck on Listview checkbox


Recommended Posts

I found a few scripts that I'm going to leverage:

and I started tweaking it and I've gotten to a point that I'm stuck. I can get the root level see if it is checked or not, but it doesn't seem to dive any further down. What I really want is to grab the entire path from the check boxes.

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#Include <GuiTreeView.au3>
#Include <File.au3>

$gui = GUICreate("File Browser", 586, 415, -1, -1)
$iTree = GUICtrlCreateTreeView(0, 0, 585, 377, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES))
$cButton = GUICtrlCreateButton("Save", 504, 384, 75, 25)
$hImage = _GUIImageList_Create(16, 16, 5, 2)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 4)
_GUIImageList_AddIcon($hImage, @SystemDir & "\shell32.dll", 54)
_GUICtrlTreeView_SetNormalImageList($iTree, $hImage)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
$root = _GUICtrlTreeView_AddChild($iTree,"","C:\",0)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            $aFolders=GetChecked($iTree)
            _ArrayDisplay($aFolders)
            For $z=0 to UBound($aFolders)-1
                FileDelete(@ScriptDir&"\FolderList.txt")
                FileWriteLine(@ScriptDir&"\FolderList.txt",$aFolders[$z])
            Next
    EndSwitch
WEnd

Func GetChecked($iTree)
    Local $aReturn[0]
    $count = _GUICtrlTreeView_GetCount($iTree)
    For $i = 0 To $count - 1
        MsgBox(0, "ischecked", $i & " = " & _GUICtrlTreeView_GetChecked($iTree, $i))
        If _GUICtrlTreeView_GetChecked($iTree, $i)=True Then
            _ArrayAdd($aReturn,_GUICtrlTreeView_GetText($iTree, $i))
        EndIf
    Next
    Return $aReturn
EndFunc

Func _SearchFolder($folder,$parent,$level=0)
    If $level >= 1 Then Return
    $files = _FileListToArray($folder,"*",1)
    $folders = _FileListToArray($folder,"*",2)
    _FolderFunc($folders,$folder,$parent,$level)
EndFunc

Func _FolderFunc($folders,$folder,$parent,$level)
    For $i = 1 To UBound($folders)-1
        $parentitem = _GUICtrlTreeView_AddChild($iTree,$parent,$folders[$i],0)
        _SearchFolder($folder & "\" & $folders[$i],$parentitem,$level+1)
    Next
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR
    $hWndTreeView = GUICtrlGetHandle($iTree)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndTreeView
            Switch $iCode
                Case -451
                    $item = _GUICtrlTreeView_GetSelection($hWndTreeView)
                    $root = $item
                    If _GUICtrlTreeView_GetChildCount($hWndTreeView,$item) <= 0 Then
                        $txt = _GUICtrlTreeView_GetText($hWndTreeView,$item)
                        Do
                            $parent = _GUICtrlTreeView_GetParentHandle($hWndTreeView,$item)
                            If $parent <> 0 Then
                                $txt = _GUICtrlTreeView_GetText($hWndTreeView,$parent) & "\" & $txt
                                $item = $parent
                            EndIf
                        Until $parent = 0
                        _SearchFolder($txt,$root)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Any idea why its not seeing that the child elements are checked off? Also, any suggestions on getting the full path for the checked off child elements?

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...