Jump to content

Recommended Posts

  • Moderators

Syed23,

how to clear my spaces which is occupied?

Go to "My Settings" and then to "Manage Attachments" - delete what ever is there and no longer required. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Replies 75
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

Syed23, Always happy to help. M23

Syed23,

Go to "My Settings" and then to "Manage Attachments" - delete what ever is there and no longer required. :)

M23

Thank you so much Melba23 and please see the attached!

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

I need more information.

Was there ever a [+] box on that branch of the tree? If not, then that indicates that the UDF got no returns using FileFindNextFile on that folder, so it thinks that there is no reason to expand it further. Is there actually something in that folder when you use another app (Explorer perhaps) to expand it? :huh:

If there was a [+] box and then it vanished when you tried to expand the branch then it must be another problem - but I have no idea what at the moment. Can you expand the other branches on the tree which do have [+] boxes?

Over to you. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

box and then it vanished when you tried to expand the branch then it must be another problem - but I have no idea what at the moment. Can you expand the other branches on the tree which do have [+] boxes?

M23

you got me perfectly! the above is happening. i could see the + symbol on Microsoft office folder. once i clicked on expand it vanished only i could see the microsoft office folder name :) hope i have explained in proper way :)

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

This is like drawing teeth one by one. ;)

Does the same thing happen when you click on the other [+] boxes? Are no folders expanded or is it just the "Microsoft Office" one? And if it is just the one, can you confirm that there is indeed something inside the folder? :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Syed23,

This is like drawing teeth one by one. ;)

Does the same thing happen when you click on the other [+] boxes? Are no folders expanded or is it just the "Microsoft Office" one? And if it is just the one, can you confirm that there is indeed something inside the folder? :huh:

M23

this is what happening for all the folders! also there are files and folders inside the "microsoft Office" folder. :)

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

Thank you for replying. :)

But I am afraid I am no wiser. I cannot understand why you can open one level of the tree and then not get any further. The UDF is obviously working initially as it expands the top level folders. As I explained earlier, the result you get is because the UDF cannot find any content within the folder you are trying to expand. :wacko:

I will be testing this in my home pc to see whether something problem with environment

Did you try at home? What happened there? :huh:

M23

P.S. Please stop quoting my posts in yours when you reply- it is very annoying. ;)

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Even in my home personal pc the behavior is same :D... really even i don't understand why this is happening to me. :( I am using Autoit V.3.3.8.1 am i doing any mistake??

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

I have asked several other people with x64 systems to try it and they cannot reproduce your symptoms. So I am very sorry but I am afraid that I have absolutely no idea why you are having this problem. :(

The following script uses exactly the same code structure as the UDF to look inside the "Microsoft Office" folder. Please adjust the path to match the one on your machine and run it:

#include <RecFileListToArray.au3>

; Adjust this to match the path on your nachine
$sPath = "C:Program FilesMicrosoft Office" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

FileChangeDir($sPath)
$hSearch = FileFindFirstFile("*")
If $hSearch = -1 Then
    MsgBox(4096, "Error", "No files/folders found")
Else
    Local $sFile = FileFindNextFile($hSearch)
    If @error Then
        MsgBox(4096, "Error", "Nothing found")
    Else
        If @extended Then
            MsgBox(4096, "Folders", "Found: " & $sFile)
        Else
            MsgBox(4096, "Files", "Found: " & $sFile)
        EndIf
    EndIf
EndIf
FileClose($hSearch)

$aContent = _RecFileListToArray($sPath, "*.*", 1)
If IsArray($aContent) Then
    MsgBox(4096, "Files", "Found: " & $aContent[0])
Else
    MsgBox(4096, "Error", "No files found")
EndIf

What MsgBoxes do you see? On my machine I get a folder ("Office") and no files. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

First think it showed a message box with titile "Folder" and message "Clipart" which is the first folder of the "Microsoft Office" folder. once i clicked on OK button it showed me another message box with title "Files" and message "Found:2". in i click ok then the tool exits. this is what happened :(

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

Interesting - the same basic code in the UDF is not finding those files and folder. :wacko:

Let me have a think about a modified UDF version with a few extra checks for you to try. Be patient. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites
  • Moderators

Syed23,

First step. :D

Run this code from within SciTE. When the dialog appears open the C: drive, expand your "Program Files" folder and then try to expand the "Microsoft Office" folder.

#include <GuiTreeView.au3>
#include "RecFileListToArray.au3"

Global $cCFF_Expand_Dummy, $cCFF_DblClk_Dummy

Func _CFF_Choose($sTitle, $iW, $iH, $iX = -1, $iY = -1, $sRoot = "", $sFile_Mask = "*", $iDisplay = 0, $iMultiple = 0, $hParent = 0)

#region
    ; Check position
    If $iX = Default Then
        $iX = -1
    EndIf
    If $iY = Default Then
        $iY = -1
    EndIf

    ; Check path
    Switch $sRoot
        Case "", Default
            $sRoot = ""
        Case Else
            If Not FileExists($sRoot) Then
                Return SetError(1, 0, "")
            EndIf
            If StringRight($sRoot, 1) <> "" Then
                $sRoot &= ""
            EndIf
    EndSwitch

    ; Check FileMask
    If $sFile_Mask = Default Then
        $sFile_Mask = "*"
    EndIf

    ; Check Display
    ; Hide file extensions?
    Local $fShow_Ext = True
    If BitAnd($iDisplay, 16) Then
        $iDisplay -= 16
        ; Check that only one ext is specified
        StringReplace($sFile_Mask, ";", "")
        Local $iExt = @extended
        If $sFile_Mask <> "*.*" And $iExt = 0 Then
            ; File exts hidden
            $fShow_Ext = False
        EndIf
    EndIf
    ; Show hiden and system files
    Local $iHide_HS = 0
    If BitAnd($iDisplay, 4) Then
        $iHide_HS += 4
        $iDisplay -= 4
    EndIf
    If BitAnd($iDisplay, 8) Then
        $iHide_HS += 8
        $iDisplay -= 8
    EndIf
    ; Check valid parameter
    Switch $iDisplay
        Case 0 To 3
            ; Valid
        Case Else
            Return SetError(2, 0, "")
    EndSwitch

    ; Check selection type and list size
    Local $fSingle_Sel = False
    Local $iList_Percent = .2
    Switch $iMultiple
        Case 0, Default
            $fSingle_Sel = True
        Case 10 To 50
            $iList_Percent = .01 * $iMultiple
    EndSwitch

    ; Check parent
    Switch $hParent
        Case 0
        Case Else
            If Not IsHWnd($hParent) Then Return SetError(3, 0, "")
    EndSwitch

    ; Check for width and height minima and set button size
    Local $iButton_Width
    If $fSingle_Sel Then
        If $iW < 130 Then $iW = 130
        $iButton_Width = Int(($iW - 30) / 2)
    Else
        If $iW < 190 Then $iW = 190
        $iButton_Width = Int(($iW - 40) / 3)
    EndIf
    If $iButton_Width > 80 Then $iButton_Width = 80
    If $iH < 300 Then $iH = 300

    ; Create dialog
    Local $hCFF_Win = GUICreate($sTitle, $iW, $iH, $iX, $iY, 0x80C80000, -1, $hParent) ; BitOR($WS_POPUPWINDOW, $WS_CAPTION)
    If @error Then Return SetError(4, 0, "")
    GUISetBkColor(0xCECECE)

    ; Declare variables
    Local $hCan_Button, $cSel_Button = 9999, $cAdd_Button = 9999, $cRet_Button = 9999
    Local $cTreeView = 9999, $hTreeView = 9999, $hList = 9999, $hDrive_Combo = 9999
    Local $sCurrDrive = "", $sSelectedPath, $iList_Height, $iTV_Height, $sAddFile_List = ""

    ; Create buttons
    If $fSingle_Sel Then
        $cSel_Button = GUICtrlCreateButton("Select", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    Else
        $cAdd_Button = GUICtrlCreateButton("Add", 10, $iH - 40, $iButton_Width, 30)
        $cRet_Button = GUICtrlCreateButton("Return", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    EndIf
    $hCan_Button = GUICtrlCreateButton("Cancel", $iW - ($iButton_Width + 10) * 2, $iH - 40, $iButton_Width, 30)

    ; Create controls
    Select
        Case $sRoot And $fSingle_Sel ; TV only
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iH - 60)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case Not $sRoot And $fSingle_Sel ; Combo and TV
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iH - 90)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case $sRoot And Not $fSingle_Sel ; TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 60) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 60
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 10 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))

        Case Not $sRoot And Not $fSingle_Sel ; Combo, TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 90) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 90
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 40 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))
    EndSelect

    ; Create dummy control to fire when [+] clicked
    $cCFF_Expand_Dummy = GUICtrlCreateDummy()
    ; Create dummy control to for on DblClk
    $cCFF_DblClk_Dummy = GUICtrlCreateDummy()

    ; Display dialog
    GUISetState()

    If $sRoot Then
        ; If root folder specified then fill TV
        _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
        ; Show TV
        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
    EndIf

    ; Change to MessageLoop mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    #endregion

    While 1

        Switch GUIGetMsg()
            Case $hCan_Button, -3 ; $GUI_EVENT_CLOSE
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(5, 0, "")

            Case $cCFF_DblClk_Dummy
                ; Check doubleclicks are permitted (not default for folders only)
                If $iDisplay <> 2 Then
                    ContinueCase
                EndIf

            Case $cSel_Button, $cAdd_Button
                ; Get item data
                Local $cItem = GUICtrlRead($cTreeView)
                Local $hItem = GUICtrlGetHandle($cItem)
                ; Determine item path
                $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $hItem), "|", "")
                ; Check path is a valid selection
                Switch $iDisplay
                    Case 2
                        ; Folders only
                    Case Else
                        ; Files only
                        StringReplace(FileGetAttrib($sSelectedPath), "D", "")
                        ; Is it a folder?
                        If @extended Then
                            $sSelectedPath = ""
                        EndIf
                        ; Hide extension?
                        If $fShow_Ext = False Then
                            $sSelectedPath &= StringTrimLeft($sFile_Mask, 1)
                        EndIf
                EndSwitch
                If $sSelectedPath Then
                    ; Valid item selected
                    If $fSingle_Sel Then
                        GUIDelete($hCFF_Win)
                        ; Restore previous mode
                        Opt('GUIOnEventMode', $nOldOpt)
                        ; Return valid path
                        Return $sSelectedPath
                    Else
                        ; Add to return string
                        $sAddFile_List &= $sSelectedPath & "|"
                        ; Add to onscreen list
                        GUICtrlSendMsg($hList, 0x0180, 0, $sSelectedPath) ; $LB_ADDSTRING
                        ; Scroll to bottom of list
                        GUICtrlSendMsg($hList, 0x197, GUICtrlSendMsg($hList, 0x18B, 0, 0) - 1, 0) ; $LB_SETTOPINDEX, $LB_GETCOUNT
                        ; Return focus to TV
                        GUICtrlSetState($cTreeView, 256) ; $GUI_FOCUS
                    EndIf
                EndIf

            Case $cRet_Button
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                ; Remove final | from return string and return
                Return StringTrimRight($sAddFile_List, 1)

            Case $cCFF_Expand_Dummy
                ; Get expanded item hamdle
                $hItem = GUICtrlRead($cCFF_Expand_Dummy)
                If $hItem Then
                    ; Select item
                    _GUICtrlTreeView_ClickItem($hTreeView, $hItem)
                    ; Get expanded item data
                    $cItem = GUICtrlRead($cTreeView)
                    $hItem = GUICtrlGetHandle($cItem)
                    $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($cTreeView, $hItem), "|", "")
                    ; Check if dummy child exists or has already been filled
                    Local $hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
                    Local $sFirstChild = _GUICtrlTreeView_GetText($hTreeView, $hFirstChild)
                    ; If dummy child exists
                    If $sFirstChild = "" Then
                        ; Fill with content
                        _CFF_Fill_Branch($hTreeView, $cItem, $sSelectedPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                        ; Delete the dummy
                        _GUICtrlTreeView_Delete($hTreeView, $hFirstChild)
                    ;Else
                        ; Either already filled or empty
                    EndIf
                    ; Clear the flag to reactivate the handler
                    GUICtrlSendToDummy($cCFF_Expand_Dummy, 0)
                EndIf

            Case $hDrive_Combo
                If GUICtrlRead($hDrive_Combo) <> $sCurrDrive Then
                    ; Get drive chosen
                    $sCurrDrive = GUICtrlRead($hDrive_Combo)
                    If $sRoot Then
                        ; Delete current content
                        _GUICtrlTreeView_DeleteAll($hTreeView)
                    Else
                        ; Show TV
                        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
                    EndIf
                    ; Set root path
                    $sRoot = $sCurrDrive & ""
                    ; Fill TV
                    _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                EndIf

        EndSwitch

    WEnd

EndFunc   ;==>_CFF_Choose

Func _CFF_RegMsg()

    Return GUIRegisterMsg(0x004E, "_CFF_WM_NOTIFY_Handler") ; $WM_NOTIFY

EndFunc   ;==>_CFF_RegMsg

Func _CFF_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
        "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
        "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
        "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
        "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
        "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hItem = DllStructGetData($tStruct, 'NewhItem')
    Local $ID = DllStructGetData($tStruct, 'Code')
    Switch $ID
        Case 0xFFFFFFFD ; $NM_DBLCLK
            ; Fire the dummy control
            GUICtrlSendToDummy($cCFF_DblClk_Dummy)
        Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA
            ; Check that expansion is not ongoing
            If GUICtrlRead($cCFF_Expand_Dummy) = 0 Then
                ; Fire the dummy control
                GUICtrlSendToDummy($cCFF_Expand_Dummy, $hItem)
            EndIf
    EndSwitch

EndFunc   ;==>_CFF_WM_NOTIFY_Handler

Func _CFF_Combo_Fill($iW)

    Local $iInset = Int(($iW - 170) / 2)

    GUICtrlCreateLabel("Select Drive:", 10 + $iInset, 15, 65, 20)
    Local $hCombo = GUICtrlCreateCombo("", 75 + $iInset, 10, 50, 20)
    Local $aDrives = DriveGetDrive("ALL")
    For $i = 1 To $aDrives[0]
        ; Only display ready drives
        If DriveStatus($aDrives[$i] & '') <> "NOTREADY" Then GUICtrlSetData($hCombo, StringUpper($aDrives[$i]))
    Next
    Return $hCombo

EndFunc   ;==>_CFF_Combo_Fill

Func _CFF_Fill_Branch($hTV, $cParent, $sPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)

    Local $sItem, $cItem, $hSearch, $FFound = False

    If StringRight($sPath, 1) <> "" Then
        $sPath &= ""
    EndIf

    _GUICtrlTreeView_BeginUpdate($hTV)
    Switch $iDisplay
        Case 0, 2, 3
            ; List folders
            Local $aContent = _RecFileListToArray($sPath, "*", 2 + $iHide_HS, 0, 1, 1)
            If IsArray($aContent) Then

                ConsoleWrite("Expanding: " & $sPath & " - found " & $aContent[0] & " folders" & @CRLF)

                For $i = 1 To $aContent[0]
                    ; Remove trailing  if needed
                    $sItem = $aContent[$i]
                    If StringRight($sItem, 1) = "" Then
                        $sItem = StringTrimRight($sItem, 1)
                    EndIf
                    ; Create item
                    $cItem = GUICtrlCreateTreeViewItem($sItem, $cParent)
                    ; Look for content within the folder
                    FileChangeDir($sPath & $aContent[$i])
                    $hSearch = FileFindFirstFile("*.*")
                    ; If there is something
                    If $hSearch <> -1 Then
                        ; Set flag
                        $fFound = True
                        ; Need to determine type of content?
                        Switch $iDisplay
                            Case 0 ; Either folder or file
                                ; Create dummy child to force [+] display
                                GUICtrlCreateTreeViewItem("", $cItem)
                            Case Else
                                While 1
                                    FileFindNextFile($hSearch)
                                    ; End of content
                                    If @error Then ExitLoop
                                    Local $iExtended = @extended
                                    Switch $iDisplay
                                        Case 1 ; Files only
                                            If Not $iExtended Then
                                                ; Found file
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                        Case Else ; Folders only
                                            If $iExtended Then
                                                ; Found folder
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                    EndSwitch
                                WEnd
                                ; Close search
                                FileClose($hSearch)
                        EndSwitch
                    EndIf
                    FileChangeDir(@ScriptDir)
                Next
            EndIf
    EndSwitch
    Switch $iDisplay
        Case 0, 1
            ; List files
            $aContent = _RecFileListToArray($sPath, $sFile_Mask, 1 + $iHide_HS, 0, 1)
            If IsArray($aContent) Then

                ConsoleWrite("Expanding: " & $sPath & " - found " & $aContent[0] & " files" & @CRLF)

                ; Set flag
                $FFound = True
                For $i = 1 To $aContent[0]
                    $sItem = $aContent[$i]
                    ; Remove extension if required
                    If Not $fShow_Ext Then
                        $sItem = StringRegExpReplace($sItem, "(.*)..*", "$1")
                    EndIf
                    ; Create item
                    GUICtrlCreateTreeViewItem($sItem, $cParent)
                Next
            EndIf
    EndSwitch
    _GUICtrlTreeView_EndUpdate($hTV)

    Return $fFound

EndFunc   ;==>_CFF_Fill_Branch

_CFF_RegMsg()

$sRet = _CFF_Choose("Syed23 Test 1", 300, 500, -1, -1, "", 0)

Please post the results that you see in the lower pane - I get: :)

Expanding: C: - found 17 folders
Expanding: C: - found 14 files
Expanding: C:Program Files - found 98 folders
Expanding: C:Program Files - found 1 files
Expanding: C:Program FilesMicrosoft Office - found 3 folders

I wonder what we will see from you? :huh:

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

i did as you said and i got the below consolewrite values until i explore Microsoft Office folder. once i expanded Microsoft Office Folder nothing happened. :D

Expanding: C: - found 20 folders
Expanding: C: - found 4 files
Expanding: C:Program Files (x86) - found 50 folders
Expanding: C:Program Files (x86) - found 1 files

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

I have added a few more checks this time - please do exactly as I asked last time: :)

#include <GuiTreeView.au3>
#include "RecFileListToArray.au3"

Global $cCFF_Expand_Dummy, $cCFF_DblClk_Dummy

Func _CFF_Choose($sTitle, $iW, $iH, $iX = -1, $iY = -1, $sRoot = "", $sFile_Mask = "*", $iDisplay = 0, $iMultiple = 0, $hParent = 0)

#region
    ; Check position
    If $iX = Default Then
        $iX = -1
    EndIf
    If $iY = Default Then
        $iY = -1
    EndIf

    ; Check path
    Switch $sRoot
        Case "", Default
            $sRoot = ""
        Case Else
            If Not FileExists($sRoot) Then
                Return SetError(1, 0, "")
            EndIf
            If StringRight($sRoot, 1) <> "" Then
                $sRoot &= ""
            EndIf
    EndSwitch

    ; Check FileMask
    If $sFile_Mask = Default Then
        $sFile_Mask = "*"
    EndIf

    ; Check Display
    ; Hide file extensions?
    Local $fShow_Ext = True
    If BitAnd($iDisplay, 16) Then
        $iDisplay -= 16
        ; Check that only one ext is specified
        StringReplace($sFile_Mask, ";", "")
        Local $iExt = @extended
        If $sFile_Mask <> "*.*" And $iExt = 0 Then
            ; File exts hidden
            $fShow_Ext = False
        EndIf
    EndIf
    ; Show hiden and system files
    Local $iHide_HS = 0
    If BitAnd($iDisplay, 4) Then
        $iHide_HS += 4
        $iDisplay -= 4
    EndIf
    If BitAnd($iDisplay, 8) Then
        $iHide_HS += 8
        $iDisplay -= 8
    EndIf
    ; Check valid parameter
    Switch $iDisplay
        Case 0 To 3
            ; Valid
        Case Else
            Return SetError(2, 0, "")
    EndSwitch

    ; Check selection type and list size
    Local $fSingle_Sel = False
    Local $iList_Percent = .2
    Switch $iMultiple
        Case 0, Default
            $fSingle_Sel = True
        Case 10 To 50
            $iList_Percent = .01 * $iMultiple
    EndSwitch

    ; Check parent
    Switch $hParent
        Case 0
        Case Else
            If Not IsHWnd($hParent) Then Return SetError(3, 0, "")
    EndSwitch

    ; Check for width and height minima and set button size
    Local $iButton_Width
    If $fSingle_Sel Then
        If $iW < 130 Then $iW = 130
        $iButton_Width = Int(($iW - 30) / 2)
    Else
        If $iW < 190 Then $iW = 190
        $iButton_Width = Int(($iW - 40) / 3)
    EndIf
    If $iButton_Width > 80 Then $iButton_Width = 80
    If $iH < 300 Then $iH = 300

    ; Create dialog
    Local $hCFF_Win = GUICreate($sTitle, $iW, $iH, $iX, $iY, 0x80C80000, -1, $hParent) ; BitOR($WS_POPUPWINDOW, $WS_CAPTION)
    If @error Then Return SetError(4, 0, "")
    GUISetBkColor(0xCECECE)

    ; Declare variables
    Local $hCan_Button, $cSel_Button = 9999, $cAdd_Button = 9999, $cRet_Button = 9999
    Local $cTreeView = 9999, $hTreeView = 9999, $hList = 9999, $hDrive_Combo = 9999
    Local $sCurrDrive = "", $sSelectedPath, $iList_Height, $iTV_Height, $sAddFile_List = ""

    ; Create buttons
    If $fSingle_Sel Then
        $cSel_Button = GUICtrlCreateButton("Select", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    Else
        $cAdd_Button = GUICtrlCreateButton("Add", 10, $iH - 40, $iButton_Width, 30)
        $cRet_Button = GUICtrlCreateButton("Return", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    EndIf
    $hCan_Button = GUICtrlCreateButton("Cancel", $iW - ($iButton_Width + 10) * 2, $iH - 40, $iButton_Width, 30)

    ; Create controls
    Select
        Case $sRoot And $fSingle_Sel ; TV only
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iH - 60)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case Not $sRoot And $fSingle_Sel ; Combo and TV
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iH - 90)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case $sRoot And Not $fSingle_Sel ; TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 60) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 60
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 10 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))

        Case Not $sRoot And Not $fSingle_Sel ; Combo, TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 90) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 90
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 40 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))
    EndSelect

    ; Create dummy control to fire when [+] clicked
    $cCFF_Expand_Dummy = GUICtrlCreateDummy()
    ; Create dummy control to for on DblClk
    $cCFF_DblClk_Dummy = GUICtrlCreateDummy()

    ; Display dialog
    GUISetState()

    If $sRoot Then
        ; If root folder specified then fill TV
        _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
        ; Show TV
        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
    EndIf

    ; Change to MessageLoop mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    #endregion

    While 1

        Switch GUIGetMsg()
            Case $hCan_Button, -3 ; $GUI_EVENT_CLOSE
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(5, 0, "")

            Case $cCFF_DblClk_Dummy
                ; Check doubleclicks are permitted (not default for folders only)
                If $iDisplay <> 2 Then
                    ContinueCase
                EndIf

            Case $cSel_Button, $cAdd_Button
                ; Get item data
                Local $cItem = GUICtrlRead($cTreeView)
                Local $hItem = GUICtrlGetHandle($cItem)
                ; Determine item path
                $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $hItem), "|", "")
                ; Check path is a valid selection
                Switch $iDisplay
                    Case 2
                        ; Folders only
                    Case Else
                        ; Files only
                        StringReplace(FileGetAttrib($sSelectedPath), "D", "")
                        ; Is it a folder?
                        If @extended Then
                            $sSelectedPath = ""
                        EndIf
                        ; Hide extension?
                        If $fShow_Ext = False Then
                            $sSelectedPath &= StringTrimLeft($sFile_Mask, 1)
                        EndIf
                EndSwitch
                If $sSelectedPath Then
                    ; Valid item selected
                    If $fSingle_Sel Then
                        GUIDelete($hCFF_Win)
                        ; Restore previous mode
                        Opt('GUIOnEventMode', $nOldOpt)
                        ; Return valid path
                        Return $sSelectedPath
                    Else
                        ; Add to return string
                        $sAddFile_List &= $sSelectedPath & "|"
                        ; Add to onscreen list
                        GUICtrlSendMsg($hList, 0x0180, 0, $sSelectedPath) ; $LB_ADDSTRING
                        ; Scroll to bottom of list
                        GUICtrlSendMsg($hList, 0x197, GUICtrlSendMsg($hList, 0x18B, 0, 0) - 1, 0) ; $LB_SETTOPINDEX, $LB_GETCOUNT
                        ; Return focus to TV
                        GUICtrlSetState($cTreeView, 256) ; $GUI_FOCUS
                    EndIf
                EndIf

            Case $cRet_Button
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                ; Remove final | from return string and return
                Return StringTrimRight($sAddFile_List, 1)

            Case $cCFF_Expand_Dummy
                ; Get expanded item hamdle
                $hItem = GUICtrlRead($cCFF_Expand_Dummy)
                If $hItem Then
                    ; Select item
                    _GUICtrlTreeView_ClickItem($hTreeView, $hItem)
                    ; Get expanded item data
                    $cItem = GUICtrlRead($cTreeView)
                    $hItem = GUICtrlGetHandle($cItem)
                    $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($cTreeView, $hItem), "|", "")
                    ; Check if dummy child exists or has already been filled
                    Local $hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
                    Local $sFirstChild = _GUICtrlTreeView_GetText($hTreeView, $hFirstChild)
                    ; If dummy child exists
                    If $sFirstChild = "" Then
                        ; Fill with content
                        _CFF_Fill_Branch($hTreeView, $cItem, $sSelectedPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                        ; Delete the dummy
                        _GUICtrlTreeView_Delete($hTreeView, $hFirstChild)
                    ;Else
                        ; Either already filled or empty
                    EndIf
                    ; Clear the flag to reactivate the handler
                    GUICtrlSendToDummy($cCFF_Expand_Dummy, 0)
                EndIf

            Case $hDrive_Combo
                If GUICtrlRead($hDrive_Combo) <> $sCurrDrive Then
                    ; Get drive chosen
                    $sCurrDrive = GUICtrlRead($hDrive_Combo)
                    If $sRoot Then
                        ; Delete current content
                        _GUICtrlTreeView_DeleteAll($hTreeView)
                    Else
                        ; Show TV
                        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
                    EndIf
                    ; Set root path
                    $sRoot = $sCurrDrive & ""
                    ; Fill TV
                    _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                EndIf

        EndSwitch

    WEnd

EndFunc   ;==>_CFF_Choose

Func _CFF_RegMsg()

    Return GUIRegisterMsg(0x004E, "_CFF_WM_NOTIFY_Handler") ; $WM_NOTIFY

EndFunc   ;==>_CFF_RegMsg

Func _CFF_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
        "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
        "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
        "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
        "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
        "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hItem = DllStructGetData($tStruct, 'NewhItem')
    Local $ID = DllStructGetData($tStruct, 'Code')
    Switch $ID
        Case 0xFFFFFFFD ; $NM_DBLCLK
            ; Fire the dummy control
            GUICtrlSendToDummy($cCFF_DblClk_Dummy)
        Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA
            ; Check that expansion is not ongoing
            If GUICtrlRead($cCFF_Expand_Dummy) = 0 Then
                ; Fire the dummy control
                GUICtrlSendToDummy($cCFF_Expand_Dummy, $hItem)
            EndIf
    EndSwitch

EndFunc   ;==>_CFF_WM_NOTIFY_Handler

Func _CFF_Combo_Fill($iW)

    Local $iInset = Int(($iW - 170) / 2)

    GUICtrlCreateLabel("Select Drive:", 10 + $iInset, 15, 65, 20)
    Local $hCombo = GUICtrlCreateCombo("", 75 + $iInset, 10, 50, 20)
    Local $aDrives = DriveGetDrive("ALL")
    For $i = 1 To $aDrives[0]
        ; Only display ready drives
        If DriveStatus($aDrives[$i] & '') <> "NOTREADY" Then GUICtrlSetData($hCombo, StringUpper($aDrives[$i]))
    Next
    Return $hCombo

EndFunc   ;==>_CFF_Combo_Fill

Func _CFF_Fill_Branch($hTV, $cParent, $sPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)

    Local $sItem, $cItem, $hSearch, $FFound = False

    If StringRight($sPath, 1) <> "" Then
        $sPath &= ""
    EndIf

    _GUICtrlTreeView_BeginUpdate($hTV)
    Switch $iDisplay
        Case 0, 2, 3

            ConsoleWrite("! Folder listing: " & $sPath & " - " & 2 + $iHide_HS & @CRLF)

            ; List folders
            Local $aContent = _RecFileListToArray($sPath, "*", 2 + $iHide_HS, 0, 1, 1)


            If IsArray($aContent) Then

                ConsoleWrite("+ Expanding: " & $sPath & " - found " & $aContent[0] & " folders" & @CRLF)

                For $i = 1 To $aContent[0]
                    ; Remove trailing  if needed
                    $sItem = $aContent[$i]
                    If StringRight($sItem, 1) = "" Then
                        $sItem = StringTrimRight($sItem, 1)
                    EndIf
                    ; Create item
                    $cItem = GUICtrlCreateTreeViewItem($sItem, $cParent)
                    ; Look for content within the folder
                    FileChangeDir($sPath & $aContent[$i])
                    $hSearch = FileFindFirstFile("*.*")
                    ; If there is something
                    If $hSearch <> -1 Then

                        If StringInStr( $sPath & $aContent[$i], "Microsoft Office") Then
                            ConsoleWrite("> Found something within: " & $sPath & $aContent[$i] & @CRLF)
                        EndIf

                        ; Set flag
                        $fFound = True
                        ; Need to determine type of content?
                        Switch $iDisplay
                            Case 0 ; Either folder or file
                                ; Create dummy child to force [+] display
                                GUICtrlCreateTreeViewItem("", $cItem)
                            Case Else
                                While 1
                                    FileFindNextFile($hSearch)
                                    ; End of content
                                    If @error Then ExitLoop
                                    Local $iExtended = @extended
                                    Switch $iDisplay
                                        Case 1 ; Files only
                                            If Not $iExtended Then
                                                ; Found file
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                        Case Else ; Folders only
                                            If $iExtended Then
                                                ; Found folder
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                    EndSwitch
                                WEnd
                                ; Close search
                                FileClose($hSearch)
                        EndSwitch
                    EndIf
                    FileChangeDir(@ScriptDir)
                Next
            EndIf
    EndSwitch
    Switch $iDisplay
        Case 0, 1
            ; List files
            $aContent = _RecFileListToArray($sPath, $sFile_Mask, 1 + $iHide_HS, 0, 1)

            ConsoleWrite("! File listing: " & $sPath & " - " & 1 + $iHide_HS & @CRLF)

            If IsArray($aContent) Then

                ConsoleWrite("+ Expanding: " & $sPath & " - found " & $aContent[0] & " files" & @CRLF)

                ; Set flag
                $FFound = True
                For $i = 1 To $aContent[0]
                    $sItem = $aContent[$i]
                    ; Remove extension if required
                    If Not $fShow_Ext Then
                        $sItem = StringRegExpReplace($sItem, "(.*)..*", "$1")
                    EndIf
                    ; Create item
                    GUICtrlCreateTreeViewItem($sItem, $cParent)
                Next
            EndIf
    EndSwitch
    _GUICtrlTreeView_EndUpdate($hTV)

    Return $fFound

EndFunc   ;==>_CFF_Fill_Branch

_CFF_RegMsg()

$sRet = _CFF_Choose("Syed23 Test 2", 300, 500, -1, -1, "", 0)

Iget:

! Folder listing: C: - 2
+ Expanding: C: - found 17 folders
! File listing: C: - 1
+ Expanding: C: - found 14 files
! Folder listing: C:Program Files - 2
+ Expanding: C:Program Files - found 98 folders
> Found something within: C:Program FilesMicrosoft Office
! File listing: C:Program Files - 1
+ Expanding: C:Program Files - found 1 files
! Folder listing: C:Program FilesMicrosoft Office - 2
+ Expanding: C:Program FilesMicrosoft Office - found 3 folders
> Found something within: C:Program FilesMicrosoft OfficeOffice
> Found something within: C:Program FilesMicrosoft OfficeOffice12
> Found something within: C:Program FilesMicrosoft OfficePowerPoint Viewer
! File listing: C:Program FilesMicrosoft Office - 1

Over to you! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

Again i did the same procedure :) here is the result..

! Folder listing: C: - 2
+ Expanding: C: - found 20 folders
! File listing: C: - 1
+ Expanding: C: - found 4 files
! Folder listing: C:Program Files (x86) - 2
+ Expanding: C:Program Files (x86) - found 50 folders
> Found something within: C:Program Files (x86)Microsoft Office
! File listing: C:Program Files (x86) - 1
+ Expanding: C:Program Files (x86) - found 1 files
! Folder listing: C:Program Files (x86)Microsoft Office - 2
! File listing: C:Program Files (x86)Microsoft Office - 1

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites

I have just noticed one think but not sure whether that makes sence or not. if i am wrong just forgive me! The back slash missing between Program Files(x86) and Microsoft Office

C:Program Files (x86)Microsoft Office

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

Well spotted! I think we are getting somewhere. :thumbsup:

Another version! :D

#include <GuiTreeView.au3>
#include "RecFileListToArray.au3"

Global $cCFF_Expand_Dummy, $cCFF_DblClk_Dummy

Func _CFF_Choose($sTitle, $iW, $iH, $iX = -1, $iY = -1, $sRoot = "", $sFile_Mask = "*", $iDisplay = 0, $iMultiple = 0, $hParent = 0)

#region
    ; Check position
    If $iX = Default Then
        $iX = -1
    EndIf
    If $iY = Default Then
        $iY = -1
    EndIf

    ; Check path
    Switch $sRoot
        Case "", Default
            $sRoot = ""
        Case Else
            If Not FileExists($sRoot) Then
                Return SetError(1, 0, "")
            EndIf
            If StringRight($sRoot, 1) <> "" Then
                $sRoot &= ""
            EndIf
    EndSwitch

    ; Check FileMask
    If $sFile_Mask = Default Then
        $sFile_Mask = "*"
    EndIf

    ; Check Display
    ; Hide file extensions?
    Local $fShow_Ext = True
    If BitAnd($iDisplay, 16) Then
        $iDisplay -= 16
        ; Check that only one ext is specified
        StringReplace($sFile_Mask, ";", "")
        Local $iExt = @extended
        If $sFile_Mask <> "*.*" And $iExt = 0 Then
            ; File exts hidden
            $fShow_Ext = False
        EndIf
    EndIf
    ; Show hiden and system files
    Local $iHide_HS = 0
    If BitAnd($iDisplay, 4) Then
        $iHide_HS += 4
        $iDisplay -= 4
    EndIf
    If BitAnd($iDisplay, 8) Then
        $iHide_HS += 8
        $iDisplay -= 8
    EndIf
    ; Check valid parameter
    Switch $iDisplay
        Case 0 To 3
            ; Valid
        Case Else
            Return SetError(2, 0, "")
    EndSwitch

    ; Check selection type and list size
    Local $fSingle_Sel = False
    Local $iList_Percent = .2
    Switch $iMultiple
        Case 0, Default
            $fSingle_Sel = True
        Case 10 To 50
            $iList_Percent = .01 * $iMultiple
    EndSwitch

    ; Check parent
    Switch $hParent
        Case 0
        Case Else
            If Not IsHWnd($hParent) Then Return SetError(3, 0, "")
    EndSwitch

    ; Check for width and height minima and set button size
    Local $iButton_Width
    If $fSingle_Sel Then
        If $iW < 130 Then $iW = 130
        $iButton_Width = Int(($iW - 30) / 2)
    Else
        If $iW < 190 Then $iW = 190
        $iButton_Width = Int(($iW - 40) / 3)
    EndIf
    If $iButton_Width > 80 Then $iButton_Width = 80
    If $iH < 300 Then $iH = 300

    ; Create dialog
    Local $hCFF_Win = GUICreate($sTitle, $iW, $iH, $iX, $iY, 0x80C80000, -1, $hParent) ; BitOR($WS_POPUPWINDOW, $WS_CAPTION)
    If @error Then Return SetError(4, 0, "")
    GUISetBkColor(0xCECECE)

    ; Declare variables
    Local $hCan_Button, $cSel_Button = 9999, $cAdd_Button = 9999, $cRet_Button = 9999
    Local $cTreeView = 9999, $hTreeView = 9999, $hList = 9999, $hDrive_Combo = 9999
    Local $sCurrDrive = "", $sSelectedPath, $iList_Height, $iTV_Height, $sAddFile_List = ""

    ; Create buttons
    If $fSingle_Sel Then
        $cSel_Button = GUICtrlCreateButton("Select", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    Else
        $cAdd_Button = GUICtrlCreateButton("Add", 10, $iH - 40, $iButton_Width, 30)
        $cRet_Button = GUICtrlCreateButton("Return", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    EndIf
    $hCan_Button = GUICtrlCreateButton("Cancel", $iW - ($iButton_Width + 10) * 2, $iH - 40, $iButton_Width, 30)

    ; Create controls
    Select
        Case $sRoot And $fSingle_Sel ; TV only
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iH - 60)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case Not $sRoot And $fSingle_Sel ; Combo and TV
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iH - 90)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case $sRoot And Not $fSingle_Sel ; TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 60) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 60
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 10 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))

        Case Not $sRoot And Not $fSingle_Sel ; Combo, TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 90) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 90
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 40 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))
    EndSelect

    ; Create dummy control to fire when [+] clicked
    $cCFF_Expand_Dummy = GUICtrlCreateDummy()
    ; Create dummy control to for on DblClk
    $cCFF_DblClk_Dummy = GUICtrlCreateDummy()

    ; Display dialog
    GUISetState()

    If $sRoot Then
        ; If root folder specified then fill TV
        _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
        ; Show TV
        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
    EndIf

    ; Change to MessageLoop mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    #endregion

    While 1

        Switch GUIGetMsg()
            Case $hCan_Button, -3 ; $GUI_EVENT_CLOSE
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(5, 0, "")

            Case $cCFF_DblClk_Dummy
                ; Check doubleclicks are permitted (not default for folders only)
                If $iDisplay <> 2 Then
                    ContinueCase
                EndIf

            Case $cSel_Button, $cAdd_Button
                ; Get item data
                Local $cItem = GUICtrlRead($cTreeView)
                Local $hItem = GUICtrlGetHandle($cItem)
                ; Determine item path
                $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $hItem), "|", "")
                ; Check path is a valid selection
                Switch $iDisplay
                    Case 2
                        ; Folders only
                    Case Else
                        ; Files only
                        StringReplace(FileGetAttrib($sSelectedPath), "D", "")
                        ; Is it a folder?
                        If @extended Then
                            $sSelectedPath = ""
                        EndIf
                        ; Hide extension?
                        If $fShow_Ext = False Then
                            $sSelectedPath &= StringTrimLeft($sFile_Mask, 1)
                        EndIf
                EndSwitch
                If $sSelectedPath Then
                    ; Valid item selected
                    If $fSingle_Sel Then
                        GUIDelete($hCFF_Win)
                        ; Restore previous mode
                        Opt('GUIOnEventMode', $nOldOpt)
                        ; Return valid path
                        Return $sSelectedPath
                    Else
                        ; Add to return string
                        $sAddFile_List &= $sSelectedPath & "|"
                        ; Add to onscreen list
                        GUICtrlSendMsg($hList, 0x0180, 0, $sSelectedPath) ; $LB_ADDSTRING
                        ; Scroll to bottom of list
                        GUICtrlSendMsg($hList, 0x197, GUICtrlSendMsg($hList, 0x18B, 0, 0) - 1, 0) ; $LB_SETTOPINDEX, $LB_GETCOUNT
                        ; Return focus to TV
                        GUICtrlSetState($cTreeView, 256) ; $GUI_FOCUS
                    EndIf
                EndIf

            Case $cRet_Button
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                ; Remove final | from return string and return
                Return StringTrimRight($sAddFile_List, 1)

            Case $cCFF_Expand_Dummy
                ; Get expanded item hamdle
                $hItem = GUICtrlRead($cCFF_Expand_Dummy)
                If $hItem Then
                    ; Select item
                    _GUICtrlTreeView_ClickItem($hTreeView, $hItem)
                    ; Get expanded item data
                    $cItem = GUICtrlRead($cTreeView)
                    $hItem = GUICtrlGetHandle($cItem)
                    $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($cTreeView, $hItem), "|", "")
                    ; Check if dummy child exists or has already been filled
                    Local $hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
                    Local $sFirstChild = _GUICtrlTreeView_GetText($hTreeView, $hFirstChild)
                    ; If dummy child exists
                    If $sFirstChild = "" Then
                        ; Fill with content
                        _CFF_Fill_Branch($hTreeView, $cItem, $sSelectedPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                        ; Delete the dummy
                        _GUICtrlTreeView_Delete($hTreeView, $hFirstChild)
                    ;Else
                        ; Either already filled or empty
                    EndIf
                    ; Clear the flag to reactivate the handler
                    GUICtrlSendToDummy($cCFF_Expand_Dummy, 0)
                EndIf

            Case $hDrive_Combo
                If GUICtrlRead($hDrive_Combo) <> $sCurrDrive Then
                    ; Get drive chosen
                    $sCurrDrive = GUICtrlRead($hDrive_Combo)
                    If $sRoot Then
                        ; Delete current content
                        _GUICtrlTreeView_DeleteAll($hTreeView)
                    Else
                        ; Show TV
                        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
                    EndIf
                    ; Set root path
                    $sRoot = $sCurrDrive & ""
                    ; Fill TV
                    _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                EndIf

        EndSwitch

    WEnd

EndFunc   ;==>_CFF_Choose

Func _CFF_RegMsg()

    Return GUIRegisterMsg(0x004E, "_CFF_WM_NOTIFY_Handler") ; $WM_NOTIFY

EndFunc   ;==>_CFF_RegMsg

Func _CFF_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
        "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
        "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
        "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
        "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
        "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hItem = DllStructGetData($tStruct, 'NewhItem')
    Local $ID = DllStructGetData($tStruct, 'Code')
    Switch $ID
        Case 0xFFFFFFFD ; $NM_DBLCLK
            ; Fire the dummy control
            GUICtrlSendToDummy($cCFF_DblClk_Dummy)
        Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA
            ; Check that expansion is not ongoing
            If GUICtrlRead($cCFF_Expand_Dummy) = 0 Then
                ; Fire the dummy control
                GUICtrlSendToDummy($cCFF_Expand_Dummy, $hItem)
            EndIf
    EndSwitch

EndFunc   ;==>_CFF_WM_NOTIFY_Handler

Func _CFF_Combo_Fill($iW)

    Local $iInset = Int(($iW - 170) / 2)

    GUICtrlCreateLabel("Select Drive:", 10 + $iInset, 15, 65, 20)
    Local $hCombo = GUICtrlCreateCombo("", 75 + $iInset, 10, 50, 20)
    Local $aDrives = DriveGetDrive("ALL")
    For $i = 1 To $aDrives[0]
        ; Only display ready drives
        If DriveStatus($aDrives[$i] & '') <> "NOTREADY" Then GUICtrlSetData($hCombo, StringUpper($aDrives[$i]))
    Next
    Return $hCombo

EndFunc   ;==>_CFF_Combo_Fill

Func _CFF_Fill_Branch($hTV, $cParent, $sPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)

    Local $sItem, $cItem, $hSearch, $FFound = False

    ConsoleWrite("Passed path = " & $sPath & @CRLF)

    If StringRight($sPath, 1) <> "" Then
        $sPath &= ""
    EndIf

    ConsoleWrite("Used path  = " & $sPath & @CRLF)

    _GUICtrlTreeView_BeginUpdate($hTV)
    Switch $iDisplay
        Case 0, 2, 3

            ;ConsoleWrite("! Folder listing: " & $sPath & " - " & 2 + $iHide_HS & @CRLF)

            ; List folders
            Local $aContent = _RecFileListToArray($sPath, "*", 2 + $iHide_HS, 0, 1, 1)


            If IsArray($aContent) Then

                ;ConsoleWrite("+ Expanding: " & $sPath & " - found " & $aContent[0] & " folders" & @CRLF)

                For $i = 1 To $aContent[0]
                    ; Remove trailing  if needed
                    $sItem = $aContent[$i]
                    If StringRight($sItem, 1) = "" Then
                        $sItem = StringTrimRight($sItem, 1)
                    EndIf
                    ; Create item
                    $cItem = GUICtrlCreateTreeViewItem($sItem, $cParent)
                    ; Look for content within the folder
                    FileChangeDir($sPath & $aContent[$i])
                    $hSearch = FileFindFirstFile("*.*")
                    ; If there is something
                    If $hSearch <> -1 Then

                        If StringInStr( $sPath & $aContent[$i], "Microsoft Office") Then
                            ;ConsoleWrite("> Found something within: " & $sPath & $aContent[$i] & @CRLF)
                        EndIf

                        ; Set flag
                        $fFound = True
                        ; Need to determine type of content?
                        Switch $iDisplay
                            Case 0 ; Either folder or file
                                ; Create dummy child to force [+] display
                                GUICtrlCreateTreeViewItem("", $cItem)
                            Case Else
                                While 1
                                    FileFindNextFile($hSearch)
                                    ; End of content
                                    If @error Then ExitLoop
                                    Local $iExtended = @extended
                                    Switch $iDisplay
                                        Case 1 ; Files only
                                            If Not $iExtended Then
                                                ; Found file
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                        Case Else ; Folders only
                                            If $iExtended Then
                                                ; Found folder
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                    EndSwitch
                                WEnd
                                ; Close search
                                FileClose($hSearch)
                        EndSwitch
                    EndIf
                    FileChangeDir(@ScriptDir)
                Next
            EndIf
    EndSwitch
    Switch $iDisplay
        Case 0, 1
            ; List files
            $aContent = _RecFileListToArray($sPath, $sFile_Mask, 1 + $iHide_HS, 0, 1)

            ;ConsoleWrite("! File listing: " & $sPath & " - " & 1 + $iHide_HS & @CRLF)

            If IsArray($aContent) Then

                ;ConsoleWrite("+ Expanding: " & $sPath & " - found " & $aContent[0] & " files" & @CRLF)

                ; Set flag
                $FFound = True
                For $i = 1 To $aContent[0]
                    $sItem = $aContent[$i]
                    ; Remove extension if required
                    If Not $fShow_Ext Then
                        $sItem = StringRegExpReplace($sItem, "(.*)..*", "$1")
                    EndIf
                    ; Create item
                    GUICtrlCreateTreeViewItem($sItem, $cParent)
                Next
            EndIf
    EndSwitch
    _GUICtrlTreeView_EndUpdate($hTV)

    Return $fFound

EndFunc   ;==>_CFF_Fill_Branch

_CFF_RegMsg()

$sRet = _CFF_Choose("Syed23 Test 3", 300, 500, -1, -1, "", 0)

I get:

Passed path = C:
Used path  = C:
Passed path = C:Program Files
Used path  = C:Program Files
Passed path = C:Program FilesMicrosoft Office
Used path  = C:Program FilesMicrosoft Office

And you ...... :huh:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to post
Share on other sites

now i ran the code again. Here is the result of the new given code..

Passed path = C:
Used path  = C:
Passed path = C:Program Files (x86)
Used path  = C:Program Files (x86)
Passed path = C:Program Files (x86)Microsoft Office
Used path  = C:Program Files (x86)Microsoft Office
Passed path = C:Program Files (x86)Microsoft Silverlight
Used path  = C:Program Files (x86)Microsoft Silverlight
Passed path = C:Program Files (x86)Microsoft SQL Server Compact Edition
Used path  = C:Program Files (x86)Microsoft SQL Server Compact Edition

Thank you,Regards,[font="Garamond"][size="4"]K.Syed Ibrahim.[/size][/font]

Link to post
Share on other sites
  • Moderators

Syed23,

Thank you for your patience. :)

One more - which I hope will give us the answer to the problem:

#include <GuiTreeView.au3>
#include "RecFileListToArray.au3"

Global $cCFF_Expand_Dummy, $cCFF_DblClk_Dummy

Func _CFF_Choose($sTitle, $iW, $iH, $iX = -1, $iY = -1, $sRoot = "", $sFile_Mask = "*", $iDisplay = 0, $iMultiple = 0, $hParent = 0)

#region
    ; Check position
    If $iX = Default Then
        $iX = -1
    EndIf
    If $iY = Default Then
        $iY = -1
    EndIf

    ; Check path
    Switch $sRoot
        Case "", Default
            $sRoot = ""
        Case Else
            If Not FileExists($sRoot) Then
                Return SetError(1, 0, "")
            EndIf
            If StringRight($sRoot, 1) <> "" Then
                $sRoot &= ""
            EndIf
    EndSwitch

    ; Check FileMask
    If $sFile_Mask = Default Then
        $sFile_Mask = "*"
    EndIf

    ; Check Display
    ; Hide file extensions?
    Local $fShow_Ext = True
    If BitAnd($iDisplay, 16) Then
        $iDisplay -= 16
        ; Check that only one ext is specified
        StringReplace($sFile_Mask, ";", "")
        Local $iExt = @extended
        If $sFile_Mask <> "*.*" And $iExt = 0 Then
            ; File exts hidden
            $fShow_Ext = False
        EndIf
    EndIf
    ; Show hiden and system files
    Local $iHide_HS = 0
    If BitAnd($iDisplay, 4) Then
        $iHide_HS += 4
        $iDisplay -= 4
    EndIf
    If BitAnd($iDisplay, 8) Then
        $iHide_HS += 8
        $iDisplay -= 8
    EndIf
    ; Check valid parameter
    Switch $iDisplay
        Case 0 To 3
            ; Valid
        Case Else
            Return SetError(2, 0, "")
    EndSwitch

    ; Check selection type and list size
    Local $fSingle_Sel = False
    Local $iList_Percent = .2
    Switch $iMultiple
        Case 0, Default
            $fSingle_Sel = True
        Case 10 To 50
            $iList_Percent = .01 * $iMultiple
    EndSwitch

    ; Check parent
    Switch $hParent
        Case 0
        Case Else
            If Not IsHWnd($hParent) Then Return SetError(3, 0, "")
    EndSwitch

    ; Check for width and height minima and set button size
    Local $iButton_Width
    If $fSingle_Sel Then
        If $iW < 130 Then $iW = 130
        $iButton_Width = Int(($iW - 30) / 2)
    Else
        If $iW < 190 Then $iW = 190
        $iButton_Width = Int(($iW - 40) / 3)
    EndIf
    If $iButton_Width > 80 Then $iButton_Width = 80
    If $iH < 300 Then $iH = 300

    ; Create dialog
    Local $hCFF_Win = GUICreate($sTitle, $iW, $iH, $iX, $iY, 0x80C80000, -1, $hParent) ; BitOR($WS_POPUPWINDOW, $WS_CAPTION)
    If @error Then Return SetError(4, 0, "")
    GUISetBkColor(0xCECECE)

    ; Declare variables
    Local $hCan_Button, $cSel_Button = 9999, $cAdd_Button = 9999, $cRet_Button = 9999
    Local $cTreeView = 9999, $hTreeView = 9999, $hList = 9999, $hDrive_Combo = 9999
    Local $sCurrDrive = "", $sSelectedPath, $iList_Height, $iTV_Height, $sAddFile_List = ""

    ; Create buttons
    If $fSingle_Sel Then
        $cSel_Button = GUICtrlCreateButton("Select", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    Else
        $cAdd_Button = GUICtrlCreateButton("Add", 10, $iH - 40, $iButton_Width, 30)
        $cRet_Button = GUICtrlCreateButton("Return", $iW - ($iButton_Width + 10), $iH - 40, $iButton_Width, 30)
    EndIf
    $hCan_Button = GUICtrlCreateButton("Cancel", $iW - ($iButton_Width + 10) * 2, $iH - 40, $iButton_Width, 30)

    ; Create controls
    Select
        Case $sRoot And $fSingle_Sel ; TV only
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iH - 60)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case Not $sRoot And $fSingle_Sel ; Combo and TV
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iH - 90)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE

        Case $sRoot And Not $fSingle_Sel ; TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 60) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 60
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 10, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 10 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))

        Case Not $sRoot And Not $fSingle_Sel ; Combo, TV and List
            ; Calculate control heights
            $iList_Height = Int(($iH - 90) * $iList_Percent)
            If $iList_Height < 40 Then
                $iList_Height = 40
            EndIf
            $iTV_Height = $iH - $iList_Height - 90
            ; Create and fill Combo
            $hDrive_Combo = _CFF_Combo_Fill($iW)
            ; Create TV and hide
            $cTreeView = GUICtrlCreateTreeView(10, 40, $iW - 20, $iTV_Height)
            $hTreeView = GUICtrlGetHandle($cTreeView)
            GUICtrlSetState(-1, 32) ; $GUI_HIDE
            ; Create List
            $hList = GUICtrlCreateList("", 10, 40 + $iTV_Height, $iW - 20, $iList_Height, 0x00A04100) ;BitOR($WS_BORDER, $WS_VSCROLL, $LBS_NOSEL, $LBS_NOINTEGRALHEIGHT))
    EndSelect

    ; Create dummy control to fire when [+] clicked
    $cCFF_Expand_Dummy = GUICtrlCreateDummy()
    ; Create dummy control to for on DblClk
    $cCFF_DblClk_Dummy = GUICtrlCreateDummy()

    ; Display dialog
    GUISetState()

    If $sRoot Then
        ; If root folder specified then fill TV
        _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
        ; Show TV
        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
    EndIf

    ; Change to MessageLoop mode
    Local $nOldOpt = Opt('GUIOnEventMode', 0)

    #endregion

    While 1

        Switch GUIGetMsg()
            Case $hCan_Button, -3 ; $GUI_EVENT_CLOSE
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                Return SetError(5, 0, "")

            Case $cCFF_DblClk_Dummy
                ; Check doubleclicks are permitted (not default for folders only)
                If $iDisplay <> 2 Then
                    ContinueCase
                EndIf

            Case $cSel_Button, $cAdd_Button
                ; Get item data
                Local $cItem = GUICtrlRead($cTreeView)
                Local $hItem = GUICtrlGetHandle($cItem)
                ; Determine item path
                $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($hTreeView, $hItem), "|", "")
                ; Check path is a valid selection
                Switch $iDisplay
                    Case 2
                        ; Folders only
                    Case Else
                        ; Files only
                        StringReplace(FileGetAttrib($sSelectedPath), "D", "")
                        ; Is it a folder?
                        If @extended Then
                            $sSelectedPath = ""
                        EndIf
                        ; Hide extension?
                        If $fShow_Ext = False Then
                            $sSelectedPath &= StringTrimLeft($sFile_Mask, 1)
                        EndIf
                EndSwitch
                If $sSelectedPath Then
                    ; Valid item selected
                    If $fSingle_Sel Then
                        GUIDelete($hCFF_Win)
                        ; Restore previous mode
                        Opt('GUIOnEventMode', $nOldOpt)
                        ; Return valid path
                        Return $sSelectedPath
                    Else
                        ; Add to return string
                        $sAddFile_List &= $sSelectedPath & "|"
                        ; Add to onscreen list
                        GUICtrlSendMsg($hList, 0x0180, 0, $sSelectedPath) ; $LB_ADDSTRING
                        ; Scroll to bottom of list
                        GUICtrlSendMsg($hList, 0x197, GUICtrlSendMsg($hList, 0x18B, 0, 0) - 1, 0) ; $LB_SETTOPINDEX, $LB_GETCOUNT
                        ; Return focus to TV
                        GUICtrlSetState($cTreeView, 256) ; $GUI_FOCUS
                    EndIf
                EndIf

            Case $cRet_Button
                GUIDelete($hCFF_Win)
                ; Restore previous mode
                Opt('GUIOnEventMode', $nOldOpt)
                ; Remove final | from return string and return
                Return StringTrimRight($sAddFile_List, 1)

            Case $cCFF_Expand_Dummy
                ; Get expanded item hamdle
                $hItem = GUICtrlRead($cCFF_Expand_Dummy)
                If $hItem Then
                    ; Select item
                    _GUICtrlTreeView_ClickItem($hTreeView, $hItem)
                    ; Get expanded item data
                    $cItem = GUICtrlRead($cTreeView)
                    $hItem = GUICtrlGetHandle($cItem)
                    $sSelectedPath = $sRoot & StringReplace(_GUICtrlTreeView_GetTree($cTreeView, $hItem), "|", "")

                    ConsoleWrite("Path received:  " & _GUICtrlTreeView_GetTree($cTreeView, $hItem) & @CRLF)
                    ConsoleWrite("Path to expand: " & $sSelectedPath & @CRLF)

                    ; Check if dummy child exists or has already been filled
                    Local $hFirstChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem)
                    Local $sFirstChild = _GUICtrlTreeView_GetText($hTreeView, $hFirstChild)
                    ; If dummy child exists
                    If $sFirstChild = "" Then
                        ; Fill with content
                        _CFF_Fill_Branch($hTreeView, $cItem, $sSelectedPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                        ; Delete the dummy
                        _GUICtrlTreeView_Delete($hTreeView, $hFirstChild)
                    ;Else
                        ; Either already filled or empty
                    EndIf
                    ; Clear the flag to reactivate the handler
                    GUICtrlSendToDummy($cCFF_Expand_Dummy, 0)
                EndIf

            Case $hDrive_Combo
                If GUICtrlRead($hDrive_Combo) <> $sCurrDrive Then
                    ; Get drive chosen
                    $sCurrDrive = GUICtrlRead($hDrive_Combo)
                    If $sRoot Then
                        ; Delete current content
                        _GUICtrlTreeView_DeleteAll($hTreeView)
                    Else
                        ; Show TV
                        GUICtrlSetState($cTreeView, 16) ; $GUI_SHOW
                    EndIf
                    ; Set root path
                    $sRoot = $sCurrDrive & ""
                    ; Fill TV
                    _CFF_Fill_Branch($hTreeView, $cTreeView, $sRoot, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)
                EndIf

        EndSwitch

    WEnd

EndFunc   ;==>_CFF_Choose

Func _CFF_RegMsg()

    Return GUIRegisterMsg(0x004E, "_CFF_WM_NOTIFY_Handler") ; $WM_NOTIFY

EndFunc   ;==>_CFF_RegMsg

Func _CFF_WM_NOTIFY_Handler($hWnd, $iMsg, $wParam, $lParam)

    #forceref $hWnd, $iMsg, $wParam

    Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
        "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
        "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
        "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
        "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
        "struct;long PointX;long PointY;endstruct", $lParam)
    Local $hItem = DllStructGetData($tStruct, 'NewhItem')
    Local $ID = DllStructGetData($tStruct, 'Code')
    Switch $ID
        Case 0xFFFFFFFD ; $NM_DBLCLK
            ; Fire the dummy control
            GUICtrlSendToDummy($cCFF_DblClk_Dummy)
        Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA
            ; Check that expansion is not ongoing
            If GUICtrlRead($cCFF_Expand_Dummy) = 0 Then
                ; Fire the dummy control
                GUICtrlSendToDummy($cCFF_Expand_Dummy, $hItem)
            EndIf
    EndSwitch

EndFunc   ;==>_CFF_WM_NOTIFY_Handler

Func _CFF_Combo_Fill($iW)

    Local $iInset = Int(($iW - 170) / 2)

    GUICtrlCreateLabel("Select Drive:", 10 + $iInset, 15, 65, 20)
    Local $hCombo = GUICtrlCreateCombo("", 75 + $iInset, 10, 50, 20)
    Local $aDrives = DriveGetDrive("ALL")
    For $i = 1 To $aDrives[0]
        ; Only display ready drives
        If DriveStatus($aDrives[$i] & '') <> "NOTREADY" Then GUICtrlSetData($hCombo, StringUpper($aDrives[$i]))
    Next
    Return $hCombo

EndFunc   ;==>_CFF_Combo_Fill

Func _CFF_Fill_Branch($hTV, $cParent, $sPath, $iDisplay, $sFile_Mask, $fShow_Ext, $iHide_HS)

    Local $sItem, $cItem, $hSearch, $FFound = False

    ;ConsoleWrite("Passed path = " & $sPath & @CRLF)

    If StringRight($sPath, 1) <> "" Then
        $sPath &= ""
    EndIf

    ;ConsoleWrite("Used path  = " & $sPath & @CRLF)

    _GUICtrlTreeView_BeginUpdate($hTV)
    Switch $iDisplay
        Case 0, 2, 3

            ;ConsoleWrite("! Folder listing: " & $sPath & " - " & 2 + $iHide_HS & @CRLF)

            ; List folders
            Local $aContent = _RecFileListToArray($sPath, "*", 2 + $iHide_HS, 0, 1, 1)


            If IsArray($aContent) Then

                ;ConsoleWrite("+ Expanding: " & $sPath & " - found " & $aContent[0] & " folders" & @CRLF)

                For $i = 1 To $aContent[0]
                    ; Remove trailing  if needed
                    $sItem = $aContent[$i]
                    If StringRight($sItem, 1) = "" Then
                        $sItem = StringTrimRight($sItem, 1)
                    EndIf
                    ; Create item
                    $cItem = GUICtrlCreateTreeViewItem($sItem, $cParent)
                    ; Look for content within the folder
                    FileChangeDir($sPath & $aContent[$i])
                    $hSearch = FileFindFirstFile("*.*")
                    ; If there is something
                    If $hSearch <> -1 Then

                        ;If StringInStr( $sPath & $aContent[$i], "Microsoft Office") Then
                            ;ConsoleWrite("> Found something within: " & $sPath & $aContent[$i] & @CRLF)
                        ;EndIf

                        ; Set flag
                        $fFound = True
                        ; Need to determine type of content?
                        Switch $iDisplay
                            Case 0 ; Either folder or file
                                ; Create dummy child to force [+] display
                                GUICtrlCreateTreeViewItem("", $cItem)
                            Case Else
                                While 1
                                    FileFindNextFile($hSearch)
                                    ; End of content
                                    If @error Then ExitLoop
                                    Local $iExtended = @extended
                                    Switch $iDisplay
                                        Case 1 ; Files only
                                            If Not $iExtended Then
                                                ; Found file
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                        Case Else ; Folders only
                                            If $iExtended Then
                                                ; Found folder
                                                GUICtrlCreateTreeViewItem("", $cItem)
                                                ; No need to look further
                                                ExitLoop
                                            EndIf
                                    EndSwitch
                                WEnd
                                ; Close search
                                FileClose($hSearch)
                        EndSwitch
                    EndIf
                    FileChangeDir(@ScriptDir)
                Next
            EndIf
    EndSwitch
    Switch $iDisplay
        Case 0, 1
            ; List files
            $aContent = _RecFileListToArray($sPath, $sFile_Mask, 1 + $iHide_HS, 0, 1)

            ;ConsoleWrite("! File listing: " & $sPath & " - " & 1 + $iHide_HS & @CRLF)

            If IsArray($aContent) Then

                ;ConsoleWrite("+ Expanding: " & $sPath & " - found " & $aContent[0] & " files" & @CRLF)

                ; Set flag
                $FFound = True
                For $i = 1 To $aContent[0]
                    $sItem = $aContent[$i]
                    ; Remove extension if required
                    If Not $fShow_Ext Then
                        $sItem = StringRegExpReplace($sItem, "(.*)..*", "$1")
                    EndIf
                    ; Create item
                    GUICtrlCreateTreeViewItem($sItem, $cParent)
                Next
            EndIf
    EndSwitch
    _GUICtrlTreeView_EndUpdate($hTV)

    Return $fFound

EndFunc   ;==>_CFF_Fill_Branch

_CFF_RegMsg()

$sRet = _CFF_Choose("Syed23 Test 5", 300, 500, -1, -1, "", 0)

ConsoleWrite(Opt("GUIDataSeparatorChar") & @CRLF)

My return:

Path received:  Program Files
Path to expand: C:Program Files
Path received:  Program Files|Microsoft Office
Path to expand: C:Program FilesMicrosoft Office
|

And now time for your contribution. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...