Jump to content
Sign in to follow this  

ListView Tile

Recommended Posts

I am trying to create a window listing all the files in a folder with the name and the icon. I want it to display in a tile view. I was able to get close by finding some existing code and playing around with it but I am lost on how to do the following. Thanks in advance for the help!

1. Set the default left click to run the application or document.

2. Some icons are missing for documents or links. How do I get the file association icons to display?

3. How do I get the tile across multiple rows with the text below the icon?

4. How can I dynamically size the window based on the number of icons?

#include <GuiListView.au3>

Opt('GUIOnEventMode', 1)

Global $aFileArray, $sFolder = @DesktopDir & '\' ;Folder to list icons from.
Global $hGui, $hList, $hListItems[1] = [1], $sDocsIcon

$hGui = GUICreate('My Apps', 420, 420)
GUISetOnEvent(-3, '_Exit')

$hList = GUICtrlCreateListView('Files', 10, 10, 400, 400, 0x0004)
_GUICtrlListView_SetExtendedListViewStyle($hList, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, _
                                          $LVS_EX_SUBITEMIMAGES, $LVS_EX_INFOTIP))
$hContextMenu = GUICtrlCreateContextMenu($hList)

GUICtrlCreateMenuItem('Open', $hContextMenu)
GUICtrlSetOnEvent(-3, '_Open')

GUICtrlCreateMenuItem('Open with Notepad', $hContextMenu)
GUICtrlSetOnEvent(-3, '_OpenWithNotepad')

$aFileArray = _FileListToArray($sFolder)
For $i = 1 To $aFileArray[0]
    $hListItems[0] += 1
    ReDim $hListItems[$hListItems[0]]
    $hListItems[$hListItems[0] - 1] = GUICtrlCreateListViewItem($aFileArray[$i], $hList)
    If StringInStr($aFileArray[$i], '.lnk', 2) Then ;If shortcut.
        $Icon = FileGetShortcut($sFolder & $aFileArray[$i])
        If Not @error Then GUICtrlSetImage($hListItems[$hListItems[0] - 1], $Icon[0], $Icon[5])
    ElseIf StringInStr($aFileArray[$i], '.doc', 2) Or StringInStr($aFileArray[$i], '.txt', 2) Then ;If .doc or .txt.
        GUICtrlSetImage($hListItems[$hListItems[0] - 1], $sDocsIcon)
    Else ;If .exe or other file type.
        ;If failed to get an icon then delete.
        If GUICtrlSetImage($hListItems[$hListItems[0] - 1], $sFolder & $aFileArray[$i]) = 0 Then GUICtrlDelete($hListItems[$hListItems[0] - 1])
_GUICtrlListView_SetView($hList, 4)

ControlClick('Custom Explorer', '', 'SysHeader321', 'Primary', 2, 45, 10) ;Resize List.

While 1

Func _Exit()
EndFunc   ;==>_Exit

Func _Open()
    $Active = StringTrimRight(GUICtrlRead(GUICtrlRead($hList)), 1)
    ShellExecute($sFolder & $Active)
EndFunc   ;==>_Open

Func _OpenWithNotepad()
    $Active = StringTrimRight(GUICtrlRead(GUICtrlRead($hList)), 1)
    ShellExecute(@SystemDir & '\notepad.exe', $sFolder & $Active)
EndFunc   ;==>_OpenWithNotepad

Func _ReduceMemory()
    Local $ai_GetCurrentProcessId = DllCall('kernel32.dll', 'int', 'GetCurrentProcessId')
    Local $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', 0x1f0fff, 'int', False, 'int', $ai_GetCurrentProcessId[0])
    Local $ai_Return = DllCall("psapi.dll", 'int', 'EmptyWorkingSet', 'long', $ai_Handle[0])
    DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $ai_Handle[0])
    Return $ai_Return[0]

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...