IanN1990 Posted June 10, 2012 Share Posted June 10, 2012 (edited) Hi, I am working on the last stage of a project now, though i thought i had it figured it turned out i needed one last past. Around a week ago someone helped me with some context menu code but now its become a little complex and over my head.Though i will keep working on this topic, i figured i would post my question here as well incase someone knew how to do it.In my old topic it relayed information about making context menus.What i would like to do is have a menu that includes all my folders down a tree path.Example#NoTrayIcon #include <GUIMenu.au3> #include <File.au3> #include <WindowsConstants.au3> Local $GUIContextMenu = GUICreate("Context Menu", 1, 1, -5, -5, $WS_POPUP, $WS_EX_TOOLWINDOW) local $MainContextMenu = GUICtrlCreateContextMenu() $LvL1Computer = GUICtrlCreateMenu("Computer", $MainContextMenu) $LvL2Desktop = GUICtrlCreateMenu("Desktop", $LvL1Computer) MutiContextMenu(@DesktopDir, $LvL2Desktop) $ret = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($MainContextMenu), $GUIContextMenu, 250, 250, 1, 1, 2) ExitScript(_GUICtrlMenu_GetItemText(GUICtrlGetHandle($MainContextMenu), $ret, False)) Func MutiContextMenu($Location, $Menu) $FileList = _FileListToArray($Location) For $i = 1 to $FileList[0] If Not(StringRight($FileList[$i], 4) = ".ini") Then GUICtrlCreateMenuItem($FileList[$i], $Menu) Next EndFunc Func ExitScript($ContextMenu) Select Case $ContextMenu = "" WinActivate("[Class:Shell_TrayWnd]") Case Else ShellExecute(@DesktopDir & "\" & $ContextMenu) EndSelect EndFuncSo this code makes a basic context menu, and makes many context items for each file/folder for the desktop but what i would like it to do is for every folder to make a context folder instead and load its files into context items for that menu.Any ideas on how i could go about it, i thought about hardcoding it but i would rather not as that means if i make any new folder i would have to recode it Edited September 8, 2012 by IanN1990 Link to comment Share on other sites More sharing options...
IanN1990 Posted June 10, 2012 Author Share Posted June 10, 2012 (edited) expandcollapse popup#NoTrayIcon #include <GUIMenu.au3> #include <File.au3> #include <WindowsConstants.au3> Local $GUIContextMenu = GUICreate("Context Menu", 1, 1, -5, -5, $WS_POPUP, $WS_EX_TOOLWINDOW) local $MainContextMenu = GUICtrlCreateContextMenu() $LvL1Computer = GUICtrlCreateMenu("Computer", $MainContextMenu) $LvL2Desktop = GUICtrlCreateMenu("Desktop", $LvL1Computer) MutiContextMenu(@DesktopDir, $LvL2Desktop, 3) $ret = _GUICtrlMenu_TrackPopupMenu(GUICtrlGetHandle($MainContextMenu), $GUIContextMenu, 250, 250, 1, 1, 2) ExitScript(_GUICtrlMenu_GetItemText(GUICtrlGetHandle($MainContextMenu), $ret, False)) Func MutiContextMenu($Directory, $LvL0ContextMenu, $Level) $LvL1FolderList = _FileListToArray($Directory,"*", 2);Level 1 Folder If IsArray($LvL1FolderList) Then ;Level 1 Array For $0 = 1 to $LvL1FolderList[0] ;Level 1 For $LvL1ContextMenu = GUICtrlCreateMenu($LvL1FolderList[$0], $Lvl0ContextMenu) If $Level >= 2 then ;Level 2 Check $LvL2FolderList = _FileListToArray($Directory & "" & $LvL1FolderList[$0],"*", 2);Level 2 Folder If IsArray($LvL2FolderList) Then ;Level 2 Array For $1 = 1 to $LvL2FolderList[0] ;Level 2 For $LvL2ContextMenu = GUICtrlCreateMenu($LvL2FolderList[$1], $LvL1ContextMenu) If $Level >= 3 then ;Level 3 Check $LvL3FolderList = _FileListToArray($Directory & "" & $LvL1FolderList[$0] & "" & $LvL2FolderList[$1],"*", 2);Level 3 Folders If IsArray($LvL3FolderList) Then ;Level 3 Array For $2 = 1 to $LvL3FolderList[0] ;Level 3 For $LvL3ContextMenu = GUICtrlCreateMenu($LvL3FolderList[$2], $LvL2ContextMenu) $LvL4FileList = _FileListToArray($Directory & "" & $LvL1FolderList[$0] & "" & $LvL2FolderList[$1],"*", 1);Level 4 Files If IsArray($LvL4FileList) Then For $D = 1 to $LvL4FileList[0] GUICtrlCreateMenuItem($LvL4FileList[$D], $LvL3ContextMenu) Next EndIf Next ;Level 3 Next EndIf ;Level 3 Array EndIf ;Level 3 End Check $LvL3FileList = _FileListToArray($Directory & "" & $LvL1FolderList[$0] & "" & $LvL2FolderList[$1],"*", 1);Level 3 Files If IsArray($LvL3FileList) Then For $C = 1 to $LvL3FileList[0] GUICtrlCreateMenuItem($LvL3FileList[$C], $LvL2ContextMenu) Next EndIf Next ;Level 2 Next EndIf ;Level 2 End Array EndIf ;Level 2 End Check $LvL2FolderList = _FileListToArray($Directory & "" & $LvL1FolderList[$0],"*", 1);Level 2 Files If IsArray($LvL2FolderList) Then For $B = 1 to $LvL2FolderList[0] GUICtrlCreateMenuItem($LvL2FolderList[$B], $LvL1ContextMenu) Next EndIf Next ;Level 1 Next $LvL1FolderList = _FileListToArray($Directory, "*", 1) ;Level 1 Files If IsArray($LvL1FolderList) Then For $A = 1 to $LvL1FolderList[0] GUICtrlCreateMenuItem($LvL1FolderList[$A], $LvL0ContextMenu) Next EndIf EndIf ;Level 1 End Array EndFunc Func ExitScript($ContextMenu) Select Case $ContextMenu = "" WinActivate("[Class:Shell_TrayWnd]") Case Else ShellExecute(@DesktopDir & "" & $ContextMenu) EndSelect EndFunc There we go, can go 4 folders down and can be called to any system directory. The code was a pain to write ^^ "As if anyone knows me they know i don't use comments as i believe if code is well written then its easy to understand thus not needing comments" but back to the orginal Post is this style the coding the only easy / practical / fast / low CPU way of getting a context menu to show files and folders ? *Edit Sorry for the bad format, every time i submit it screws up >< NEW PROBLEM Func ExitScript($ContextMenu) Select Case $ContextMenu = "" WinActivate("[Class:Shell_TrayWnd]") Case Else ShellExecute(@DesktopDir & "" & $ContextMenu) EndSelect EndFunc[/autoit] Before, as the context menu was only loading desktop when a file was selected $ContextMenu became the selected item and it was ShellExecuted but now the context menus branch off into different folders and i dont know how to catch the needed information to load it Edited June 11, 2012 by IanN1990 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