Del Posted May 14, 2006 Share Posted May 14, 2006 (edited) Hi, I'm writing a program which is very similar to Windows Explorer, instead of displaying actual folders on the HDD it will show Virtual Folders. The files in a virtual folder can be from any directory. What I want to know is how to place icons in the right hand pane as it is in Windows Explorer in detail view. Edit: I've searched the forums and the help file without any success I'm sorry if this has been asked before but I couldn't find the answer This .ini is needed: [Root] Folder1 = Folder 1 Folder2 = Folder 2 [Folder 1] File1 = c:\test.txt File2 = c:\program files\test.exe [Folder 2] Save it as VirtFolders.ini This is the source: expandcollapse popup#cs Virtual Folders. Add files from various sources to a virtual folder so that they can be used as if they are in the same folder and Keep them in 'one' place for easy management. #ce #Include <GUIConstants.au3> #Include <Array.au3> BuildGUI() while 1 $Msg = GUIGetMsg() $TreeViewFolder = GetTreeViewFolder($Msg) if $TreeViewFolder <> "" then ShowFolderContents($TreeViewFolder) endif Select case $Msg = $GUI_EVENT_CLOSE GUIExit() break case $Msg = $FileMenuExit GUIExit() break case $Msg = $FileMenuOpenFolder FileMenuOpenFolder() break case $Msg = $FileMenuCloseFolder FileMenuCloseFolder() break case $Msg = $FileMenuNewFolder FileMenuNewFolder() break case $Msg = $FileMenuDeleteFolder FileMenuDeleteFolder() break case $Msg = $EditMenuAddFile EditMenuAddFile() break case $Msg = $EditMenuDeleteFile EditMenuDeleteFile() break case $Msg = $EditMenuCopyFile EditMenuCopyFile() break case $Msg = $EditMenuCutFile EditMenuCutFile() break case $Msg = $EditMenuPasteFile EditMenuPasteFile() break EndSelect wend exit #cs ================================================================ Title BuildGUI() Global(s) $FileMenu : CtrlID $FileMenuOpenFolder : CtrlID $FileMenuCloseFolder : CtrlID $FileMenuNewFolder : CtrlID $FileMenuDeleteFolder : CtrlID $FileMenuExit : CtrlID $FileMenuRecentFolders : CtrlID $EditMenu : CtrlID $EditMenuAddFile : CtrlID $EditMenuDeleteFile : CtrlID $EditMenuCopyFile : CtrlID $EditMenuCutFile : CtrlID $EditMenuPasteFile : CtrlID $ExplorerTree : CtrlID $FileListDisplay : CtrlID Local(s) $Seperator : CtrlID Parameter(s) None Notes Creates the main GUI ================================================================ #ce Func BuildGUI() global $FileListDisplay,$EditMenu, $EditMenuAddFile, $EditMenuCopyFile, $EditMenuCutFile, $EditMenuDeleteFile, $EditMenuPasteFile, $ExplorerTree, $FileDeleteFolder, $FileMenu, $FileMenuCloseFolder, $FileMenuDeleteFolder, $FileMenuExit, $FileMenuNewFolder, $FileMenuOpenFolder, $FileMenuRecentFolders, $MainWin $MainWin = GUiCreate("Virtual Folders", @DesktopWidth, @DesktopHeight) ;File Menu $FileMenu = GuiCtrlCreateMenu ("&File") $FileMenuOpenFolder = GUICtrlCreateMenuItem("Open Virtual Folder", $FileMenu) $FileMenuCloseFolder = GUICtrlCreateMenuItem("Close Virtual Folder", $FileMenu) $FileMenuNewFolder = GUICtrlCreateMenuItem("New Virtual Folder", $FileMenu) $FileMenuDeleteFolder = GUICtrlCreateMenuItem("Delete Folder", $FileMenu) $Seperator = GUICtrlCreateMenuItem("", $FileMenu) $FileMenuExit = GUICtrlCreateMenuItem("Exit", $FileMenu) ; File Menu Submenu $FileMenuRecentFolders = GUICtrlCreateMenu ("Recent Folders", $FileMenu, 4) ; ; Edit Menu $EditMenu = GUICtrlCreateMenu ("&Edit") $EditMenuAddFile = GUICtrlCreateMenuItem("Add File To Folder", $EditMenu) $EditMenuDeleteFile = GUICtrlCreateMenuItem("Delete File From Folder", $EditMenu) $EditMenuCopyFile = GUICtrlCreateMenuItem("Copy File", $EditMenu) $EditMenuCutFile = GUICtrlCreateMenuItem("Cut File", $EditMenu) $EditMenuPasteFile = GUICtrlCreateMenuItem("Paste File", $EditMenu) ; Tree View - Folder Explorer $ExplorerTree = GUICtrlCreateTreeView(5, 5, @DesktopWidth / 4, @DesktopHeight - 70, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) InitPopulateExplorerTree() ; File Display window $FileListDisplay = GUICtrlCreateListView("File|Path", 265, 5, (@Desktopwidth / 4) * 3, @DesktopHeight - 70) ; Set Option Routines GUISetState(@SW_SHOW) EndFunc #cs ================================================================ Title InitPopulateExplorerTree Global(s) FolderData : Array, CtrlID : Holds the names of all the folders in dimension 1 and The CtrlIDs in dimension 2. Local(s) None Parameter(s) None Notes This array is created here rather than PopulateExplorerTree to avoid repeated redimming of the array. The array index is held in [0][0] ================================================================ #ce Func InitPopulateExplorerTree() local $Tmp $Tmp = IniReadSectionNames("VirtFolders.ini") global $FolderData[$Tmp[0]][2] $FolderData[0][0] = 1 PopulateExplorerTree("Root", $ExplorerTree) EndFunc #cs ================================================================ Title PopulateExplorerTree Local(s) $FolderCount : Numvar $FolderName : String $Dir : String $FolderID : CtrlID $ID : CtrlID Parameter(s) $Dir : String : Folder Name to be added to the treeview $ID : CtrlID : ID of the treeview folder which the new folder will be added Notes Build Explorer Folders from VirtFolders.ini. Recursive scan of VirtFolders.ini. ================================================================ #ce ; IniRead ( "filename", "section", "key", "default" ) Func PopulateExplorerTree($Dir, $ID) local $FolderCount, $FolderId, $FolderName, $Idx, $Tmp while $FolderName <> "Not Found" $FolderCount = $FolderCount + 1 $FolderName = IniRead("VirtFolders.ini", $Dir, "Folder" & $FolderCount, "Not Found") if $FolderName <> "Not Found" then $FolderId = GUICtrlCreateTreeViewITem($FolderName, $ID) $Idx = $FolderData[0][0] $FolderData[$Idx][0] = $FolderName $FolderData[$Idx][1] = $FolderID $FolderData[0][0] = $FolderData[0][0] + 1 PopulateExplorerTree($FolderName, $FolderId) endif wend EndFunc #cs ================================================================ Title GetTreeViewFolder Local(s) $n : Loop Ctrl Parameter(s) $ID : CtrlID : ID of clicked Control Notes Returns the folder name highlighted in the TreeViewList. Compares $ID to elements of FolderData[$x][$1] and returns the folder name if found or an empty string if not found ================================================================ #ce Func GetTreeViewFolder($ID) local $n for $n = 1 to UBound($FolderData) - 1 if $ID = $FolderData[$n][1] then return $FolderData[$n][0] endif next return EndFunc #cs ================================================================ Title ShowFolderContents Global(s) Local(s) Parameter(s) FolderName Notes Populate File ListView Pane. ================================================================ #ce Func ShowFolderContents($Folder) Local $FileCount,$FileNames,$Tmp,$n,$FolderNames,$CompleteList,$FilePath,$Path Global $ListItem For $n= 1 to UBound($ListItem)-1 GUICtrlDelete($ListItem[$n]) Next $FileNames=GetItems("File",$Folder) $FolderNames=GetItems("Folder",$Folder) $CompleteList=$FolderNames & "|" & $FileNames $Tmp = StringSplit($CompleteList,"|") Global $ListItem[$Tmp[0]] for $n = 1 to $Tmp[0]-1 $Path = StringSplit($Tmp[$n],"#") If $Path[0] = 1 Then $ListItem[$n] = GUICtrlCreateListViewItem($Path[1], $FileListDisplay) else $ListItem[$n] = GUICtrlCreateListViewItem($Path[1] & "|" & $Path[2], $FileListDisplay) GUICtrlSetImage($ListItem[$n],$Tmp[$n]) EndIf GUISetState() next EndFunc ; Func GetItems($Type,$Folder) Local $Item,$Count,$Item,$Tmp,$Names,$Path While $Item <> "Not Found" $Count = $Count+1 $Item = IniRead("VirtFolders.ini",$Folder,$Type & $Count,"Not Found") If $Item <> "Not Found" Then $Tmp=StringSplit($Item,"\") $Path = "" For $n=1 to $Tmp[0] - 1 $Path = $Path & $Tmp[$n] & "\" Next $Names = $Names & $Tmp[$Tmp[0]] & "#" & $Path & "|" Endif Wend Return $Names EndFunc #cs ================================================================ ToolBar Menu Item Routines ================================================================ #ce Func FileMenuOpenFolder() EndFunc Func FileMenuCloseFolder() EndFunc Func FileMenuNewFolder() EndFunc Func FileMenuDeleteFolder() EndFunc Func EditMenuAddFile() EndFunc Func EditMenuDeleteFile() EndFunc Func EditMenuCopyFile() EndFunc Func EditMenuCutFile() EndFunc Func EditMenuPasteFile() EndFunc #cs ================================================================ Title GUIExit Notes Exit routine, close GUI, Save .ini file etc ================================================================ #ce Func GUIExit() GUIDelete() exit EndFunc #cs ================================================================ Title DebugShowError Notes if an error has occured Show Message box with error code. ================================================================ #ce Func DebugShowError() if @error = 0 then return endif MsgBox(16, "VF Error", @error) EndFunc Thanks for any help Edited May 14, 2006 by Del Link to comment Share on other sites More sharing options...
ptrex Posted May 16, 2006 Share Posted May 16, 2006 Hi, An explorer has already been made before, look here maybe you can learn from this. expandcollapse popupinclude <GUIConstants.au3> #Include <GuiListView.au3> #Include <String.au3> #include <File.au3> #include <array.au3> Opt("GUIOnEventMode", 1) Opt("MustDeclareVars", 1); Variables must be pre-declared Opt("TrayIconHide", 1); Hide the AutoIt tray icon Dim $frmExplorer, $cmdParentDir, $cmdCut, $cmdCopy, $cmdPaste, $lvwFiles, $iColWidth, $cmdAddress, $txtAddress Dim $sCurrDirPath = "C:\" $frmExplorer = GUICreate("", 545, 412, (@DesktopWidth - 545) / 2, (@DesktopHeight - 412) / 2, $WS_SYSMENU) GUISetOnEvent($GUI_EVENT_CLOSE, "frmExplorer_Unload") GUISetOnEvent($GUI_EVENT_SECONDARYUP, "frmExplorer_ContextMenuHandler") GUISetOnEvent($GUI_EVENT_MOUSEMOVE, "frmExplorer_MouseHover") GUISetIcon("icons\1.ico", 0) GUICtrlCreateMenu("&File", -1) GUICtrlCreateMenu("&Edit", -1) ; Toolbar buttons GUICtrlCreateGroup("", 0, 0, 537, 44) GUICtrlCreateButton("", 2, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\5.ico", 0, 0) GUICtrlCreateButton("", 33, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\6.ico", 0, 0) $cmdParentDir = GUICtrlCreateButton("", 64, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\7.ico", 0, 0) GuiCtrlSetOnEvent(-1, "cmdParentDir_Click") $cmdCut = GUICtrlCreateButton("", 106, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\8.ico", 0, 0) $cmdCopy = GUICtrlCreateButton("", 137, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\9.ico", 0, 0) $cmdPaste = GUICtrlCreateButton("", 168, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\10.ico", 0, 0) GUICtrlCreateButton("", 210, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\11.ico", 0, 0) GUICtrlCreateButton("", 241, 9, 32, 32, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\12.ico", 0, 0) GUICtrlCreateGroup("", 0, 36, 537, 34) GUICtrlCreateLabel("A&ddress", 8, 48, 45, 20) GUICtrlSetFont(-1, 8.5, 400, 0, "Tahoma") $txtAddress = GUICtrlCreateInput("", 55, 46, 452, 20) $cmdAddress = GUICtrlCreateButton("", 509, 46, 22, 20, $BS_ICON + $BS_FLAT) GUICtrlSetImage(-1, "icons\4.ico", 0, 0) GuiCtrlSetOnEvent(-1, "cmdAddress_Click") _RefreshFileList($sCurrDirPath) GUISwitch($frmExplorer) GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func frmExplorer_Unload() Exit EndFunc Func _RefreshFileList($sDirPath) Local $hFileList, $sFileName, $sFileAttrib, $sFileSize, $iColWidth Local $asPathSplit[5], $asIconInfo[3] GUICtrlDelete($lvwFiles) If StringInstr($sDirPath, "\", 0, 2) = 0 Then GUISetIcon("icons\1.ico", 0) Else GUISetIcon("icons\13.ico", 4) EndIf $lvwFiles = GUICtrlCreateListView("Name|Size|Type|Attributes", 0, 70, 537, 297, _ 0 + $LVS_NOSORTHEADER, $LVS_EX_TRACKSELECT + $LVS_EX_TWOCLICKACTIVATE + $WS_EX_CLIENTEDGE) ; Size column is right justified _GUICtrlListViewJustifyColumn ($lvwFiles, 1, 1) ; $lvwFiles Formatting $iColWidth = (500 / 4) - 1 For $i = 0 to 3 _GUICtrlListViewSetColumnWidth($lvwFiles, $i, $iColWidth) Next ; Default File Icon GUICtrlSetImage($lvwFiles, "shell32.dll", 0) ; Clear $lvwFiles _GUICtrlListViewDeleteAllItems($lvwFiles) GUICtrlSetData($txtAddress, $sDirPath) ; Add directories $hFileList = FileFindFirstFile($sDirPath & "\*.*") If $hFileList = -1 Then Return EndIf GUISetCursor(15, 1) While 1 $sFileName = FileFindNextFile($hFileList) If @error Then ExitLoop $sFileAttrib = FileGetAttrib($sDirPath & $sFileName) If StringInStr($sFileAttrib, "D") <> 0 Then If $sFileName = "." Or $sFileName = ".." Then ; Don't add to list Else GUICtrlCreateListViewItem($sFileName & "||File Folder|" & $sFileAttrib, $lvwFiles) GUICtrlSetImage(-1, "icons\2.ico") GuiCtrlSetOnEvent(-1, "lvwFolderItem_Click") EndIf EndIf WEnd FileClose($hFileList) ; Add files $hFileList = FileFindFirstFile($sDirPath & "\*.*") If $hFileList = -1 Then Return EndIf While 1 $sFileName = FileFindNextFile($hFileList) If @error Then ExitLoop $sFileAttrib = FileGetAttrib($sDirPath & $sFileName) If StringInStr($sFileAttrib, "D") = 0 Then $sFileSize = Round(FileGetSize($sDirPath & $sFileName) / 1024, 1) & " KB" $asPathSplit = _PathSplit($sFileName, $asPathSplit[1], $asPathSplit[2], $asPathSplit[3], $asPathSplit[4]) If $asPathSplit[4] = ".EXE" Then GUICtrlCreateListViewItem($sFileName & "|" & $sFileSize & "||" & $sFileAttrib, $lvwFiles) GUICtrlSetImage(-1, $sDirPath & $sFileName, 0) GuiCtrlSetOnEvent(-1, "lvwFileItem_Click") Else $asIconInfo = _GetAssociatedIcon($asPathSplit[4]) GUICtrlCreateListViewItem($sFileName & "|" & $sFileSize & "||" & $sFileAttrib, $lvwFiles) GUICtrlSetImage(-1, $asIconInfo[1], $asIconInfo[2]) GuiCtrlSetOnEvent(-1, "lvwFileItem_Click") EndIf EndIf WEnd FileClose($hFileList) GUISetCursor(6, 1) EndFunc Func cmdParentDir_Click() $sCurrDirPath = _PathFull($sCurrDirPath & "..\") _RefreshFileList($sCurrDirPath) GUICtrlSetState($lvwFiles, $GUI_FOCUS) EndFunc Func lvwFolderItem_Click() Local $iSelFolder, $sDirPath $iSelFolder = _GUICtrlListViewGetCurSel($lvwFiles) $sCurrDirPath = $sCurrDirPath & _GUICtrlListViewGetItemText($lvwFiles, $iSelFolder, 0) & "\" _RefreshFileList($sCurrDirPath) EndFunc Func cmdAddress_Click() GUICtrlSetData($txtAddress, _StringProper(GUICtrlRead($txtAddress))) If StringRight(GUICtrlRead($txtAddress), 1) <> "\" Then GUICtrlSetData($txtAddress, GUICtrlRead($txtAddress) & "\") EndIf $sCurrDirPath = GUICtrlRead($txtAddress) _RefreshFileList($sCurrDirPath) EndFunc Func _GetAssociatedIcon($sFileExt) Local $sFileType, $sIconInfo, $asIconInfo[3] For $i = 0 to 2 $asIconInfo[$i] = "" Next $sFileType = RegRead("HKCR\" & $sFileExt, "") If $sFileType <> "" Then $sIconInfo = RegRead("HKCR\" & $sFileType & "\DefaultIcon", "") If $sIconInfo <> "" Then $asIconInfo = StringSplit($sIconInfo, ",") If @error Then ReDim $asIconInfo[3] $asIconInfo[0] = "2" $asIconInfo[1] = _ExpandEnvStrings(FileGetLongName($sIconInfo)) $asIconInfo[2] = "0" EndIf EndIf EndIf Return $asIconInfo EndFunc Func _ExpandEnvStrings($sInput) Local $aPart = StringSplit($sInput,'%') If @error Then SetError(1) Return $sInput EndIf Dim $sOut = $aPart[1], $i = 2, $env = '' ;loop through the parts While $i <= $aPart[0] $env = EnvGet($aPart[$i]) If $env <> '' Then ;this part is an expandable environment variable $sOut = $sOut & $env $i = $i + 1 If $i <= $aPart[0] Then $sOut = $sOut & $aPart[$i] ElseIf $aPart[$i] = '' Then ;a double-percent is used to force a single percent $sOut = $sOut & '%' $i = $i + 1 If $i <= $aPart[0] Then $sOut = $sOut & $aPart[$i] Else;this part is to be returned literally $sOut = $sOut & '%' & $aPart[$i] EndIf EndIf EndIf $i = $i + 1 WEnd Return $sOut EndFunc Func frmExplorer_ContextMenuHandler() Local $asCurInfo[5], $sFileName $asCurInfo = GUIGetCursorInfo() If _GUICtrlListViewGetHotItem($lvwFiles) <> -1 Then $sFileName = $sCurrDirPath & _GUICtrlListViewGetItemText($lvwFiles, _GUICtrlListViewGetHotItem($lvwFiles), 0) DllCall("Cfexpmnu.dll", "int", "DoExplorerMenu", "hwnd", $frmExplorer, "str", $sFileName, _ "long", $asCurInfo[0], "long", $asCurInfo[1]) EndIf EndFunc Func lvwFileItem_Click() Local $sFileName $sFileName = $sCurrDirPath & _GUICtrlListViewGetItemText($lvwFiles, _GUICtrlListViewGetHotItem($lvwFiles), 0) Run(@ComSpec & " /c " & $sFileName, $sCurrDirPath, @SW_HIDE) EndFunc Func frmExplorer_MouseHover() EndFunc If you see my signature look for Firewall Log Analyser. In that script I added Icons to a listView record. So a simular function can be used to add icons to other controls. Enjoy !! Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Del Posted May 16, 2006 Author Share Posted May 16, 2006 I searched, honestly I did. Thanks for the reply, ptrex; it's much appreciated. I've had a quick glance at the listing you posted and it seems to have the things I need I'll take a look at your FW log analyzer as well. Thanks again, Del. Link to comment Share on other sites More sharing options...
Del Posted May 18, 2006 Author Share Posted May 18, 2006 (edited) Thanks, I've got it working now Your help is appreciated Edited May 18, 2006 by Del Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now