Beege

Explorer ListView UDF

13 posts in this topic

#1 ·  Posted (edited)

Here is a UDF I created to help me simplify creating MS Explorer-like ListViews.. It handles a lot of the overhead involved with working with them. Please let me know if theres something you don't understand or think I didnt explain well enough. Explaining things is always the hardest part for me.

post-8949-12651517825352_thumb.png

Example

#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <ExpListView.au3>

OnAutoItExitRegister('_Exit')
Global $sRestore = @ScriptDir & '\Restore.ini'

$hGUI = GUICreate("GUI", 849, 417)
Global $hList1 = _ExpListView_Create($hGUI, 'c:\', 13, False, 29, 43, 385, 253)
Global $hList2 = _ExpListView_Create($hGUI, 'My Computer', 28, False, 437, 43, 385, 253)

;This restores the columns to whatever they were the last time you exited the script.
;see exit function for saving views.
If FileExists($sRestore) Then
    _ExpListView_ColumnViewsRestore($hList1, IniRead($sRestore, 'ListViews', 'List1', ''))
    _ExpListView_ColumnViewsRestore($hList2, IniRead($sRestore, 'ListViews', 'List2', ''))
EndIf

Global $sCurrentDirectory1 = GUICtrlCreateLabel("", 72, 12, 344, 26)
Global $sCurrentDirectory2 = GUICtrlCreateLabel("", 477, 13, 344, 26)
$setColunms1 = GUICtrlCreateButton("Set Columns", 138, 330, 67, 25, $WS_GROUP)
$Checkbox1 = GUICtrlCreateCheckbox("Size", 138, 360, 79, 19)
$Checkbox2 = GUICtrlCreateCheckbox("Modified", 234, 330, 79, 19)
$Checkbox3 = GUICtrlCreateCheckbox("Attributes", 330, 330, 79, 19)
$Checkbox4 = GUICtrlCreateCheckbox("Creation", 234, 360, 79, 19)
$Checkbox5 = GUICtrlCreateCheckbox("Accessed", 330, 360, 79, 19)
$Back1 = GUICtrlCreateButton("Back", 42, 312, 61, 25, $WS_GROUP)
$Label1 = GUICtrlCreateLabel("Current:", 30, 12, 38, 17)
$Label3 = GUICtrlCreateLabel("Current:", 435, 13, 38, 17)
$Group1 = GUICtrlCreateGroup("Colunms", 126, 306, 289, 91)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$ShowHidden1 = GUICtrlCreateButton("Hidden", 42, 342, 61, 25, $WS_GROUP)
$input1 = GUICtrlCreateButton("Input", 42, 372, 61, 25, $WS_GROUP)
$Group2 = GUICtrlCreateGroup("Colunms", 534, 306, 289, 91)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$setColunms2 = GUICtrlCreateButton("Set Columns", 546, 330, 67, 25, $WS_GROUP)
$Checkbox6 = GUICtrlCreateCheckbox("Size", 546, 360, 79, 19)
$Checkbox7 = GUICtrlCreateCheckbox("Modified", 642, 330, 79, 19)
$Checkbox8 = GUICtrlCreateCheckbox("Attributes", 738, 330, 79, 19)
$Checkbox9 = GUICtrlCreateCheckbox("Creation", 642, 360, 79, 19)
$Checkbox10 = GUICtrlCreateCheckbox("Accessed", 738, 360, 79, 19)
$Back2 = GUICtrlCreateButton("Back", 450, 312, 61, 25, $WS_GROUP)
$ShowHidden2 = GUICtrlCreateButton("Hidden", 450, 342, 61, 25, $WS_GROUP)
$input2 = GUICtrlCreateButton("Input", 450, 372, 61, 25, $WS_GROUP)
GUICtrlSetData($sCurrentDirectory1, _ExpListView_DirGetCurrent($hList1))
GUICtrlSetData($sCurrentDirectory2, _ExpListView_DirGetCurrent($hList2))


;Here I set a function to update the Current Directory everytime the user changes directory by double clicking.
;This function is ONLY called on a double click event. Each Listview could have its own function if needed.
_ExpListView_SetFunction($hList1, '_Call_Function')
_ExpListView_SetFunction($hList2, '_Call_Function')

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Back1
            _ExpListView_Back($hList1)
            GUICtrlSetData($sCurrentDirectory1, _ExpListView_DirGetCurrent($hList1))
        Case $Back2
            _ExpListView_Back($hList2)
            GUICtrlSetData($sCurrentDirectory2, _ExpListView_DirGetCurrent($hList2))
        Case $setColunms1
            Local $iColumn_Value = 0
            If GUICtrlRead($Checkbox1) = $GUI_CHECKED Then $iColumn_Value += 1
            If GUICtrlRead($Checkbox2) = $GUI_CHECKED Then $iColumn_Value += 2
            If GUICtrlRead($Checkbox3) = $GUI_CHECKED Then $iColumn_Value += 4
            If GUICtrlRead($Checkbox4) = $GUI_CHECKED Then $iColumn_Value += 8
            If GUICtrlRead($Checkbox5) = $GUI_CHECKED Then $iColumn_Value += 16
            _ExpListView_SetColumns($hList1, $iColumn_Value)
        Case $setColunms2
            Local $iColumn_Value = 0
            If GUICtrlRead($Checkbox6) = $GUI_CHECKED Then $iColumn_Value += 1
            If GUICtrlRead($Checkbox7) = $GUI_CHECKED Then $iColumn_Value += 2
            If GUICtrlRead($Checkbox8) = $GUI_CHECKED Then $iColumn_Value += 4
            If GUICtrlRead($Checkbox9) = $GUI_CHECKED Then $iColumn_Value += 8
            If GUICtrlRead($Checkbox10) = $GUI_CHECKED Then $iColumn_Value += 16
            _ExpListView_SetColumns($hList2, $iColumn_Value)
        Case $ShowHidden1
            Local $flag = _ToggleHidden($hList1)
            _ExpListView_ShowHiddenFiles($hList1, $flag)
            _ExpListView_Refresh($hList1)
        Case $ShowHidden2
            Local $flag = _ToggleHidden($hList2)
            _ExpListView_ShowHiddenFiles($hList2, $flag)
            _ExpListView_Refresh($hList2)
        Case $input1
            Local $inputbox = InputBox('Directory Change', 'Enter the Directory to Navigate to:', '', ' M', Default, 130)
            _ExpListView_DirSetCurrent($hList1, $inputbox)
            GUICtrlSetData($sCurrentDirectory1, _ExpListView_DirGetCurrent($hList1))
        Case $input2
            Local $inputbox = InputBox('Directory Change', 'Enter the Directory to Navigate to:', '', ' M', Default, 130)
            _ExpListView_DirSetCurrent($hList2, $inputbox)
            GUICtrlSetData($sCurrentDirectory2, _ExpListView_DirGetCurrent($hList2))
    EndSwitch
WEnd

;hWnd is the only parameter needed for the call function you create.
Func _Call_Function($hWnd)
    Switch $hWnd
        Case $hList1
            GUICtrlSetData($sCurrentDirectory1, _ExpListView_DirGetCurrent($hWnd))
        Case $hList2
            GUICtrlSetData($sCurrentDirectory2, _ExpListView_DirGetCurrent($hWnd))
    EndSwitch
EndFunc   ;==>_Call_Function

Func _ToggleHidden($List)
    Static $bFlag1 = -1, $bFlag2 = -1

    Switch $List
        Case $hList1
            $bFlag1 *= -1
            If $bFlag1 = -1 Then Return False
        Case $hList2
            $bFlag2 *= -1
            If $bFlag2 = -1 Then Return False
    EndSwitch

    Return True

EndFunc   ;==>_ToggleHidden

;Here we have a simple exit function that saves the column info so we can reload it at startup.
Func _Exit()
    If Not FileExists($sRestore) Then _FileCreate($sRestore)
    IniWrite($sRestore, 'ListViews', 'List1', _ExpListView_ColumnViewsSave($hList1))
    IniWrite($sRestore, 'ListViews', 'List2', _ExpListView_ColumnViewsSave($hList2))
EndFunc   ;==>_Exit

UDF

#Region Header

; #INDEX# =======================================================================================================================
; Title .........: ExpListView
; AutoIt Version : 3.3.5.0
; Language ......: English
; Description ...: Functions for working with Explorer ListViews.
; Author(s) .....: Beege
; ===============================================================================================================================

; #CURRENT# =====================================================================================================================
; _ExpListView_Create
; _ExpListView_Back
; _ExpListView_DirGetCurrent
; _ExpListView_DirSetCurrent
; _ExpListView_SetColumns
; _ExpListView_SetFunction
; _ExpListView_ShowHiddenFiles
; _ExpListView_Refresh
; _ExpListView_ColumnViewsSave
; _ExpListView_ColumnViewsRestore
; ===============================================================================================================================

#include-once
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <array.au3>

GUIRegisterMsg($WM_NOTIFY, "EXPLORER_WM_NOTIFY")
OnAutoItExitRegister('__EXIT')

#EndRegion Header

#Region Global Variables and Constants

Global $Shell32 = DllOpen('shell32.dll')
Global Const $FOLDER_ICON_INDEX = _GUIImageList_GetFileIconIndex(@SystemDir, 0, 1)
Global $aListViews[1][7] = [[0, 'Current Dir', 'Dir History', 'Columns', 'Function', 'ColumnWidths', 'ShowHidden']]

#cs

    $aListViews[0][0]       = List Count
    [0][1-6]    = Nothing

    $aListViews[$i][0]  = hwnd
    [$i][1]     = Current Directory
    [$i][2]     = Directory History
    [$i][3]     = Columns-Value  :filesize = 1, modified = 2,Attributes = 4, Creation = 8, Accessed = 16
    [$i][4]     = Function to Call
    [$i][5]     = Column Widths
    [$i][6]     = Show Hidden Files Flag

#ce

#EndRegion Global Variables and Constants
#Region Public Functions
; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_Create
; Description ...: Create a ExpListView control
; Syntax.........: _ExpListView_Create($hWnd, $sStartDir, $iColumns, $bShowHidden = False, $iX = 1, $iY = 1, [, $iWidth = 150[, $iHeight = 150[, $iStyle = 0x0000000D[, $iExStyle = 0x00000000[, $fCoInit = False]]]]])
; Parameters ....: $hWnd        - Handle to parent or owner window
;                  $sStartDir   - Directory to start ListView in
;                  $iColumns    - This Flag value indicates which columns will be displayed. See Remarks
;                  $bShowHidden - This Flag value indicates weather hidden files will be displayed or not.
;                  $iX          - Horizontal position of the control
;                  $iY          - Vertical position of the control
;                  $iWidth      - Control width
;                  $iHeight     - Control height
;                  $iStyle      - Control styles: See _GUICtrlListView_Create() for Styles
;                  $iExStyle    - Extended control styles. See _GUICtrlListView_Create() for Extended Styles
;                  $fCoInit     - Initializes the COM library for use by the calling thread.
; Return values .: Success      - Handle to the ListView control
;                  Failure      - 0
; Author ........: Beege
; Remarks .......: The iColumns flag parameter can be a combination of the following values added together:
;                   1 - File Size
;                   2 - Last Modified
;                   4 - Attributes
;                   8 - Creation
;                   16 - Last Accessed
;                   Ex: If you wanted to show columns File size, Attributes and Creation, Flag Value would be 1+4+8 = 13
; Related .......: _GUICtrlListView_Create
; ===============================================================================================================================
Func _ExpListView_Create($hWnd, $sStartDir, $iColumns, $bShowHidden = False, $iX = 1, $iY = 1, $iWidth = 150, $iHeight = 150, $iStyle = 0x0000000D, $iExStyle = 0x00000000, $fCoInit = False)
    Local $hListView = _GUICtrlListView_Create($hWnd, 'Name', $iX, $iY, $iWidth, $iHeight, $iStyle, $iExStyle, $fCoInit)
    If $hListView = 0 Then Return SetError(1, @extended, 0)
    _GUICtrlListView_SetImageList($hListView, _GUIImageList_GetSystemImageList(), 1)
    ReDim $aListViews[UBound($aListViews) + 1][UBound($aListViews, 2)]
    $aListViews[0][0] += 1
    $aListViews[$aListViews[0][0]][0] = $hListView
    $aListViews[$aListViews[0][0]][1] = $sStartDir
    $aListViews[$aListViews[0][0]][5] = '50;50;50;50;50'
    $aListViews[$aListViews[0][0]][6] = $bShowHidden
    _ExpListView_SetColumns($hListView, $iColumns, False)
    _ChangeDir($aListViews[0][0], $sStartDir, False)
    Return $hListView
EndFunc   ;==>_ExpListView_Create

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_Back
; Description ...: Navigates ListView Back to previous Directorys
; Syntax.........: _ExpListView_Back($hWnd)
; Parameters ....: $hWnd            - HWnd returned from _ExpListView_Create()
; Return values .: Success      - 1
;                  Failure      - 0  and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: Function returns a 2 and does not set error if the History Stack is Empty
; ===============================================================================================================================
Func _ExpListView_Back($hWnd)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    Local $sPop = _HistoryPoP($iArrayIndex)
    If $sPop = -1 Then Return 2;History Stack is empty
    _ChangeDir($iArrayIndex, $sPop, False)
    Return 1
EndFunc   ;==>_ExpListView_Back

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_DirGetCurrent
; Description ...: Gets ListView Current Directory
; Syntax.........: _ExpListView_DirGetCurrent($hWnd)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
; Return values .: Success      - Directory Name
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: -
; ===============================================================================================================================
Func _ExpListView_DirGetCurrent($hWnd)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    Return $aListViews[$iArrayIndex][1]
EndFunc   ;==>_ExpListView_DirGetCurrent

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_DirSetCurrent
; Description ...: Sets ListView Current Directory
; Syntax.........: _ExpListView_DirSetCurrent($hWnd, $sDirectory)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
; Return values .: Success      - 1
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: -
; ===============================================================================================================================
Func _ExpListView_DirSetCurrent($hWnd, $sDirectory)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    If Not FileExists($sDirectory) Then Return SetError(2, @extended, 0) ;invalad Directory
    _ChangeDir($iArrayIndex, $sDirectory)
    Return 1
EndFunc   ;==>_ExpListView_DirSetCurrent

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_SetColumns
; Description ...: Sets ListView Column Flag value indicating which columns to show.
; Syntax.........: _ExpListView_SetColumns($hWnd, $iColunms, $bRefresh = True)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
;                  $iColumns    - Column Flag Value. See Remarks
;                  $bRefresh    - Flag indicating weather to refresh listview after setting columns
; Return values .: Success      - 1
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: The iColumns flag parameter can be a combination of the following values:
;                   1  - File Size
;                   2  - Last Modified
;                   4  - Attributes
;                   8  - Creation
;                   16 - Last Accessed
;                   Ex: If you wanted to show columns File size, Attributes and Creation, Flag Value would be 1+4+8 = 13
; ===============================================================================================================================
Func _ExpListView_SetColumns($hWnd, $iColunms, $bRefresh = True)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd

    _SaveColunmWidths($iArrayIndex, $hWnd)
    $aListViews[$iArrayIndex][3] = $iColunms

    _SetColumnsWidths($iArrayIndex, $hWnd)

    If $bRefresh Then _ChangeDir($iArrayIndex, $aListViews[$iArrayIndex][1], False)
    Return 1
EndFunc   ;==>_ExpListView_SetColumns

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_SetFunction
; Description ...: Sets a function to call after a Double-Click(Navigation) Event has happened.
; Syntax.........: _ExpListView_SetFunction($hWnd, $sFunction)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
;                  $sFunction   - Function to Call
; Return values .: Success      - 1
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: User function needs to have one parameter. That parameter is the Hwnd of the ListView that recived the Event.
;                   Ex:     Func MyUserFunction($hWndListView)
;                           ...
;                           EndFunc
; ===============================================================================================================================
Func _ExpListView_SetFunction($hWnd, $sFunction)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    $aListViews[$iArrayIndex][4] = $sFunction
    Return 1
EndFunc   ;==>_ExpListView_SetFunction

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_ShowHiddenFiles
; Description ...: Sets Current ListView Directory
; Syntax.........: _ExpListView_ShowHiddenFiles($hWnd, $bShowHidden)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
;                  $bShowHidden - This Flag value indicates weather hidden files will be displayed or not. True or False
; Return values .: Success      - 1
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
;                               - 2 Invalid Flag
; Author ........: Beege
; Remarks .......: ExpListViews are created with default showhidden flag being False
; ===============================================================================================================================
Func _ExpListView_ShowHiddenFiles($hWnd, $bShowHidden)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    If $bShowHidden Or Not $bShowHidden Then
        $aListViews[$iArrayIndex][6] = $bShowHidden
        Return 1
    EndIf
    Return SetError(2, @extended, 0);invalad Flag
EndFunc   ;==>_ExpListView_ShowHiddenFiles

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_Refresh
; Description ...: Refreshes ExpListView
; Syntax.........: _ExpListView_Refresh($hWnd)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
; Return values .: Success      - 1
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: -
; ===============================================================================================================================
Func _ExpListView_Refresh($hWnd)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    _ChangeDir($iArrayIndex, $aListViews[$iArrayIndex][1], False)
EndFunc   ;==>_ExpListView_Refresh

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_ColumnViewsSave
; Description ...: Gets string representing info about column widths and values
; Syntax.........: _ExpListView_ColumnViewsSave($hWnd)
; Parameters ....: $hWnd        - HWnd returned from _ExpListView_Create()
; Return values .: Success      - String
;                  Failure      - 0 and sets @ERROR:
;                               - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: String is to be used with _ExpListView_ColumnViewsRestore() function.
; ===============================================================================================================================
Func _ExpListView_ColumnViewsSave($hWnd)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    _SaveColunmWidths($iArrayIndex, $hWnd)
    Return ($aListViews[$iArrayIndex][3] & '|' & _GUICtrlListView_GetColumnWidth($hWnd, 0) & '|' & $aListViews[$iArrayIndex][5])
EndFunc   ;==>_ExpListView_ColumnViewsSave

; #FUNCTION# ====================================================================================================================
; Name...........: _ExpListView_ColumnViewsRestore
; Description ...: Restores ExpListViews Columns and Column Sizes
; Syntax.........: _ExpListView_ColumnViewsRestore($hWnd, $sColumnViews)
; Parameters ....: $hWnd            - HWnd returned from _ExpListView_Create()
;                  $sColumnViews    - String Returned from _ExpListView_ColumnViewsSave()
; Return values .: Success          - String
;                  Failure          - 0 and sets @ERROR:
;                                   - 1 Invalid hWnd
; Author ........: Beege
; Remarks .......: -
; ===============================================================================================================================
Func _ExpListView_ColumnViewsRestore($hWnd, $sColumnViews)
    Local $iArrayIndex = _GetIndex($hWnd)
    If $iArrayIndex = -1 Then Return SetError(1, @extended, 0);invald hWnd
    Local $aSplit = StringSplit($sColumnViews, '|')
    _GUICtrlListView_SetColumnWidth($hWnd, 0, $aSplit[2])
    $aListViews[$iArrayIndex][5] = $aSplit[3]
    _SetColumnsWidths($iArrayIndex, $hWnd)
    _ExpListView_SetColumns($hWnd, $aSplit[1])
EndFunc   ;==>_ExpListView_ColumnViewsRestore
#EndRegion Public Functions

#Region Internal Functions
Func EXPLORER_WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $iCode = DllStructGetData($tNMHDR, "Code")
    If $iCode = $NM_DBLCLK Then ; Sent by a list-view control when the user double-clicks an item with the left mouse button
        Local $hWndFrom, $tInfo, $iArrayIndex
        $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
        $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
        $iArrayIndex = _GetIndex($hWndFrom)
        _GetChangeDir($iArrayIndex, DllStructGetData($tInfo, "Index"))
        If $aListViews[$iArrayIndex][4] <> '' Then Call($aListViews[$iArrayIndex][4], $hWndFrom)
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>EXPLORER_WM_NOTIFY
Func _SetColumnsWidths($iArrayIndex, $hWnd)
    Local $iColumnCount = _GUICtrlListView_GetColumnCount($hWnd)
    For $i = 1 To $iColumnCount
        _GUICtrlListView_DeleteColumn($hWnd, 1)
    Next

    Local $aColumnWidths = StringSplit($aListViews[$iArrayIndex][5], ';')
    If BitAND($aListViews[$iArrayIndex][3], 1) Then _GUICtrlListView_AddColumn($hWnd, 'Size', Int($aColumnWidths[1]))
    If BitAND($aListViews[$iArrayIndex][3], 2) Then _GUICtrlListView_AddColumn($hWnd, 'Modified', Int($aColumnWidths[2]))
    If BitAND($aListViews[$iArrayIndex][3], 4) Then _GUICtrlListView_AddColumn($hWnd, 'Attributes', Int($aColumnWidths[3]))
    If BitAND($aListViews[$iArrayIndex][3], 8) Then _GUICtrlListView_AddColumn($hWnd, 'Creation', Int($aColumnWidths[4]))
    If BitAND($aListViews[$iArrayIndex][3], 16) Then _GUICtrlListView_AddColumn($hWnd, 'Accessed', Int($aColumnWidths[5]))
EndFunc   ;==>_SetColumnsWidths
Func _SaveColunmWidths($iArrayIndex, $hWnd)
    Local $i, $aColumnWidths, $iColunmValue = 1, $iColunmIndex = 1
    $aColumnWidths = StringSplit($aListViews[$iArrayIndex][5], ';')

    For $i = 1 To 5
        If BitAND($aListViews[$iArrayIndex][3], $iColunmValue) Then
            $aColumnWidths[$i] = _GUICtrlListView_GetColumnWidth($hWnd, $iColunmIndex)
            $iColunmIndex += 1
        EndIf
        $iColunmValue += $iColunmValue
    Next

    $aListViews[$iArrayIndex][5] = _ArrayToString($aColumnWidths, ';', 1)
EndFunc   ;==>_SaveColunmWidths
Func _GetIndex($hWnd)
    Local $i
    For $i = 1 To $aListViews[0][0]
        If $aListViews[$i][0] = $hWnd Then Return $i
    Next
    Return -1
EndFunc   ;==>_GetIndex
Func _ParentDirectory($iArrayIndex)
    Local $aDirSplit, $sChangeDir
    $aDirSplit = StringSplit($aListViews[$iArrayIndex][1], '\')
    If $aDirSplit[0] = 2 Then
        If $aDirSplit[2] = '' Then
            $sChangeDir = 'My Computer'
        Else
            $sChangeDir = $aDirSplit[1] & '\'
        EndIf
    Else
        For $i = 1 To $aDirSplit[0] - 1
            $sChangeDir &= $aDirSplit[$i] & '\'
        Next
        $sChangeDir = StringTrimRight($sChangeDir, 1)
    EndIf
    _ChangeDir($iArrayIndex, $sChangeDir)
EndFunc   ;==>_ParentDirectory
Func _GetChangeDir($iArrayIndex, $iListIndex)
    Local $sChangeDir, $sItemText = _GUICtrlListView_GetItemText($aListViews[$iArrayIndex][0], $iListIndex)
    Select
        Case $sItemText = '[..]'
            _ParentDirectory($iArrayIndex)
            Return
        Case $aListViews[$iArrayIndex][1] = 'My Computer'
            $sChangeDir = StringMid($sItemText, StringInStr($sItemText, '(') + 1, 2) & '\'
        Case Else
            If StringRight($aListViews[$iArrayIndex][1], 1) = '\' Then
                $sChangeDir = $aListViews[$iArrayIndex][1] & $sItemText
            Else
                $sChangeDir = $aListViews[$iArrayIndex][1] & '\' & $sItemText
            EndIf
            If StringInStr(FileGetAttrib($sChangeDir), 'D') = 0 Then Return
    EndSelect
    _ChangeDir($iArrayIndex, $sChangeDir)
EndFunc   ;==>_GetChangeDir
Func _ChangeDir($iArrayIndex, $sDirectory, $bPushHistory = True)
    If $sDirectory = 'My Computer' Then
        If $bPushHistory Then _HistoryPush($iArrayIndex, $aListViews[$iArrayIndex][1])
        _MyComputer($iArrayIndex)
        Return
    EndIf

    Local $aList, $sFile, $sAttributes, $iIcon, $iItem, $iSize, $aTime, $iColumnIndex = 1
    _GUICtrlListView_DeleteAllItems($aListViews[$iArrayIndex][0])
    $aList = _FileListToArray_mod($sDirectory)
    _GUICtrlListView_BeginUpdate($aListViews[$iArrayIndex][0])
    _GUICtrlListView_AddItem($aListViews[$iArrayIndex][0], "[..]", $FOLDER_ICON_INDEX)

    If IsArray($aList) Then
        For $i = 1 To $aList[0]
            $sFile = $sDirectory & '\' & $aList[$i]
            $sAttributes = FileGetAttrib($sFile)
            If Not $aListViews[$iArrayIndex][6] Then;ShowHidden
                If StringInStr($sAttributes, 'H') > 0 Then ContinueLoop
            EndIf
            If StringInStr($sAttributes, 'D') > 0 Then
                $iIcon = $FOLDER_ICON_INDEX
            Else
                $iIcon = _GUIImageList_GetFileIconIndex($aList[$i])
            EndIf
            $iItem = _GUICtrlListView_AddItem($aListViews[$iArrayIndex][0], $aList[$i], $iIcon)
            ;
            If BitAND($aListViews[$iArrayIndex][3], 1) Then ;size
                If $iIcon = $FOLDER_ICON_INDEX Then
                    _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $iItem, 'DIR', $iColumnIndex)
                Else
                    $iSize = FileGetSize($sFile)
                    _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $iItem, _bytes($iSize), $iColumnIndex)
                EndIf
                $iColumnIndex += 1
            EndIf
            If BitAND($aListViews[$iArrayIndex][3], 2) Then ;Modified
                $aTime = FileGetTime($sFile, 0)
                _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $iItem, $aTime[0] & '/' & $aTime[1] & '/' & $aTime[2] & ' ' & $aTime[3] & ':' & $aTime[4] & ':' & $aTime[5], $iColumnIndex)
                $iColumnIndex += 1
            EndIf
            If BitAND($aListViews[$iArrayIndex][3], 4) Then ;Attributes
                _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $iItem, $sAttributes, $iColumnIndex)
                $iColumnIndex += 1
            EndIf

            If BitAND($aListViews[$iArrayIndex][3], 8) Then;Creation
                $aTime = FileGetTime($sFile, 1)
                _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $iItem, $aTime[0] & '/' & $aTime[1] & '/' & $aTime[2] & ' ' & $aTime[3] & ':' & $aTime[4] & ':' & $aTime[5], $iColumnIndex)
                $iColumnIndex += 1
            EndIf
            If BitAND($aListViews[$iArrayIndex][3], 16) Then;Accessed
                $aTime = FileGetTime($sFile, 2)
                _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $iItem, $aTime[0] & '/' & $aTime[1] & '/' & $aTime[2] & ' ' & $aTime[3] & ':' & $aTime[4] & ':' & $aTime[5], $iColumnIndex)
                $iColumnIndex += 1
            EndIf
            $iColumnIndex = 1
        Next
    EndIf
    _GUICtrlListView_EndUpdate($aListViews[$iArrayIndex][0])
    If $bPushHistory Then _HistoryPush($iArrayIndex, $aListViews[$iArrayIndex][1])
    $aListViews[$iArrayIndex][1] = $sDirectory
EndFunc   ;==>_ChangeDir
Func _MyComputer($iArrayIndex)
    Local $drives, $attributes, $item, $Time, $iColunmIndex = 1
    $aListViews[$iArrayIndex][1] = 'My Computer'
    _GUICtrlListView_DeleteAllItems($aListViews[$iArrayIndex][0])
    $drives = DriveGetDrive("ALL")
    For $i = 1 To $drives[0]
        $item = _GUICtrlListView_AddItem($aListViews[$iArrayIndex][0], DriveGetLabel($drives[$i] & '\') & ' (' & StringUpper($drives[$i]) & ')', _GUIImageList_GetFileIconIndex($drives[$i] & '\'))
        If BitAND($aListViews[$iArrayIndex][3], 1) Then ;size
            _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $item, 'DIR', $iColunmIndex)
            $iColunmIndex += 1
        EndIf
        If BitAND($aListViews[$iArrayIndex][3], 2) Then $iColunmIndex += 1;Modified
        If BitAND($aListViews[$iArrayIndex][3], 4) Then;Attributes
            $attributes = FileGetAttrib($drives[$i] & '\')
            _GUICtrlListView_AddSubItem($aListViews[$iArrayIndex][0], $item, $attributes, $iColunmIndex)
        EndIf
        $iColunmIndex = 1
    Next
EndFunc   ;==>_MyComputer
Func _HistoryPush($iArrayIndex, $sDir)
    $aListViews[$iArrayIndex][2] = $sDir & '|' & $aListViews[$iArrayIndex][2]
EndFunc   ;==>_HistoryPush
Func _HistoryPoP($iArrayIndex)
    Local $aSplit = StringSplit($aListViews[$iArrayIndex][2], '|', 2)
    If $aSplit[0] = '' Then Return -1
    Local $sReturn = $aSplit[0]
    _ArrayDelete($aSplit, 0)
    $aListViews[$iArrayIndex][2] = _ArrayToString($aSplit, '|')
    Return $sReturn
EndFunc   ;==>_HistoryPoP
Func _FileListToArray_mod($sPath, $sFilter = "*", $iFlag = 0)
    Local $hSearch, $sFile, $sFileList, $sFolderList, $sDelim = "|"
    $sPath = StringRegExpReplace($sPath, "[\\/]+\z", "") & "\" ; ensure single trailing backslash
    If Not FileExists($sPath) Then Return SetError(1, 1, "")
    If StringRegExp($sFilter, "[\\/:><\|]|(?s)\A\s*\z") Then Return SetError(2, 2, "")
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
    $hSearch = FileFindFirstFile($sPath & $sFilter)
    If @error Then Return SetError(4, 4, "")
    While 1
        $sFile = FileFindNextFile($hSearch)
        If @error Then ExitLoop
        If @extended Then
            $sFolderList &= $sDelim & $sFile
        Else
            $sFileList &= $sDelim & $sFile
        EndIf
    WEnd
    FileClose($hSearch)
    $sFileList = $sFolderList & $sFileList
    If Not $sFileList Then Return SetError(4, 4, "")
    Return StringSplit(StringTrimLeft($sFileList, 1), "|")
EndFunc   ;==>_FileListToArray_mod
Func _bytes($iBytes)
    Switch $iBytes
        Case 0 To 1023
            Return $iBytes & " Bytes"
        Case 1024 To 1048575
            Return Round($iBytes / 1024, 2) & " KB"
        Case 1048576 To 1073741823
            Return Round($iBytes / 1048576, 2) & " MB"
        Case Else
            Return Round($iBytes / 1073741824, 2) & " GB"
    EndSwitch
EndFunc   ;==>_bytes
Func __EXIT()
    DllClose($Shell32)
EndFunc   ;==>__EXIT
;Originally written by Prog@ndy
Func _GUIImageList_GetSystemImageList($bLargeIcons = False)
    Local $SHGFI_USEFILEATTRIBUTES = 0x10, $SHGFI_SYSICONINDEX = 0x4000, $SHGFI_SMALLICON = 0x1;, $SHGFI_LARGEICON = 0x0;,$FILE_ATTRIBUTE_NORMAL = 0x80
    Local $FileInfo = DllStructCreate("dword hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];")
    Local $dwFlags = BitOR($SHGFI_USEFILEATTRIBUTES, $SHGFI_SYSICONINDEX)
    If Not ($bLargeIcons) Then $dwFlags = BitOR($dwFlags, $SHGFI_SMALLICON)
    Local $hIml = _WinAPI_SHGetFileInfo(".txt", $FILE_ATTRIBUTE_NORMAL, DllStructGetPtr($FileInfo), DllStructGetSize($FileInfo), $dwFlags)
    Return $hIml
EndFunc   ;==>_GUIImageList_GetSystemImageList
Func _GUIImageList_GetFileIconIndex($sFileSpec, $bLargeIcons = False, $bForceLoadFromDisk = False);modified
    Static $FileInfo = DllStructCreate("dword hIcon; int iIcon; DWORD dwAttributes; CHAR szDisplayName[255]; CHAR szTypeName[80];")
    Local $dwFlags = BitOR(0x4000, 0x1)
    If Not $bForceLoadFromDisk Then $dwFlags = BitOR($dwFlags, 0x10)
    DllCall($Shell32, "DWORD*", "SHGetFileInfo", "str", $sFileSpec, "DWORD", $FILE_ATTRIBUTE_NORMAL, "ptr", DllStructGetPtr($FileInfo), "UINT", DllStructGetSize($FileInfo), "UINT", $dwFlags)
    If @error Then Return SetError(1, 0, -1)
    Return DllStructGetData($FileInfo, "iIcon")
EndFunc   ;==>_GUIImageList_GetFileIconIndex
Func _WinAPI_SHGetFileInfo($pszPath, $dwFileAttributes, $psfi, $cbFileInfo, $uFlags)
    Local $return = DllCall($Shell32, "DWORD*", "SHGetFileInfo", "str", $pszPath, "DWORD", $dwFileAttributes, "ptr", $psfi, "UINT", $cbFileInfo, "UINT", $uFlags)
    If @error Then Return SetError(@error, 0, 0)
    Return $return[0]
EndFunc   ;==>_WinAPI_SHGetFileInfo
#EndRegion Internal Functions

ExpListView.au3

Edited by Beege

Share this post


Link to post
Share on other sites



I can see where this may be useful. Great job!


[font="Verdana"] [size="2"]"[/size][/font]Failure is not an option -- it comes packaged with Windows"[font="Verdana"][size="2"] Gecko Web Browser[/size][/font][font="Verdana"][size="2"], [/size][/font][font="Verdana"][size="2"]Yahtzee![/size][/font][font="Verdana"][size="2"], Toolbar Launcher (like RocketDock)[/size][/font][font="Verdana"][size="2"]Internet Blocker, Simple Calculator, Local Weather, Easy GDI+ GUI [/size][/font][font="Verdana"][size="2"]Triangle Solver, TCP File Transfer, [/size][/font][font="Verdana"][size="2"]Valuater's Autoit Wrappers[/size][/font][font="Verdana"][size="3"][size="2"][size="2"]OOP In AutoIt[/size][/size][/size][/font][font="Verdana"][size="2"][size="1"]Using Windows XP SP3, 1GB RAM, AMD Athlon Processor @ 2.1 GHzCheck me out at gadgets.freehostrocket.com[/size][/size][/font]

Share this post


Link to post
Share on other sites

I can see where this may be useful. Great job!

Yes! Somebody commented! :D Thankyou

Share this post


Link to post
Share on other sites

Great job, can you add support for List view ($LVS_LIST)

when i add $LVS_LIST in style, it's work but the column size is too small.

Share this post


Link to post
Share on other sites

Great job, can you add support for List view ($LVS_LIST)

when i add $LVS_LIST in style, it's work but the column size is too small.

Thankyou, but I don't think $LVS_LIST is suppost to show column's. Its suppost to wrap the files around. Just like how windows won't show columns if you have your folderview set to list.

Share this post


Link to post
Share on other sites

Thankyou, but I don't think $LVS_LIST is suppost to show column's. Its suppost to wrap the files around. Just like how windows won't show columns if you have your folderview set to list.

yes, i speak english very bad, see attached image for understand.

top listview is windows explorer, file appair complete.

down listview is your UDF, file is cut.

post-55441-1266185739053_thumb.jpg

Share this post


Link to post
Share on other sites

Oh you want to be able to see the whole filename. I'm not to sure if I will have any control over that. The main function uses function _GUICtrlListView_Create(). If your script looks the same when you use that function then most likely it will be out of my hands, but I'll look.

Share this post


Link to post
Share on other sites

Maybe I'm just being stupid here, but I can't seem to get the explorer gui control to dock at all. Is this a bug? Or perhaps it's just some fault of my own.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

What do you mean dock? And I cant tell if something is a bug with out seeing the code.

Edited by Beege

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

i tell you what would be great. support of simulated directories

eg a server sends a bunch of file names and the client program receves this and uses it in an explorer listview or maby the index of a compressed file is read and displayed in an explorer listview

Edit : Did not make sence

Edited by sycam0inc

All my projects live on github

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Is it possible to have folders like used in windows explorer's tile view?

Edited by Biatu

What is what? What is what.

Share this post


Link to post
Share on other sites

Does anyone have any experience  using the Explorer ListView UDF in a tab. I've muddled around trying to implement it but with no success. I feel that I'm breaking something in the UDF. My skill level or lack there of is hindering me.The attached file is basically the example file thrown into a tabbed GUI created in Koda. The only thing that I changed in the example was to point line 30 and 31 to $TabSheet1 instead of $hGUI. 

Thanks for any help is offered.

explorer listview with tabs.au3

Share this post


Link to post
Share on other sites

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now