Here it is, some icons wont work, but it works
Code:
#SingleInstance,Force
CoordMode,Menu,Screen ;show the menu at screen position
Menu,Tray,UseErrorLevel ;to continue on errors
msgbox,Use Win+Space to activate the menu
return
#space::CreateMenuSingleFolder() ;createmore of these like, !#P::CreateMenuSingleFolder(A_ProgramFiles "\")
CreateMenuSingleFolder(Foldername = "") {
global
if (Foldername = "")
{
Browse1:=A_ScriptDir "\"
Foldername:=A_ScriptDir "\"
}
Menu,Browse,add ; Add the menu to avoid error when deleting a nonexisting one
menu,Browse,delete
StringGetPos, l, Foldername,\,R,1
if (StrLen(Foldername)=3)
Menu,Browse,add,DezeComputer ..\,BrowseBack
else if l>"1"
{
Menu,Browse,add,% SubStr(Foldername,1,l+1) " ..\",BrowseBack
Menu,Browse,Icon,% SubStr(Foldername,1,l+1) " ..\",Icons\up.ico,1,24
}
else { ;if we are here somethings wrong wont you think
Menu,Browse,add,?????? ..\,BrowseBack
Menu,Browse,Icon,?????? ..\,Icons\up.ico,1,24
}
Loop %Foldername%*.* ,1
{
; msgbox A_LoopFileAttrib-%A_LoopFileAttrib%
ItemName:=A_LoopFileName
Browse0:=A_Index+1
Browse%Browse0%:=A_LoopFileName
Menu,Browse,Add,%A_LoopFileName%,BrowseMenuClicked
if InStr(A_LoopFileAttrib, "D") ;if it is a directory
{
IniRead,FolderIcon,%A_LoopFileLongPath%\Desktop.ini,.ShellClassInfo,IconFile,0 ;read the Foldericon if posible
if FolderIcon ; if there was a icon specified
{
if (SubStr(FolderIcon, 1 , 1)="\") ;if 1 char = \ set the var from the root
FolderIcon:=SubStr(A_LoopFileLongPath, 1 , 2) FolderIcon
else if (SubStr(FolderIcon, 1 , 2)=".\")
StringReplace,FolderIcon,FolderIcon,.\,%A_LoopFileLongPath%\,1
else if (SubStr(FolderIcon, 1 , 3)="..\")
FolderIcon:=GetFullName( A_LoopFileLongPath "\" FolderIcon ) IconFile=%FolderIcon%
else IfExist,% A_LoopFileLongPath "\" FolderIcon
FolderIcon:=A_LoopFileLongPath "\" FolderIcon
IfExist,%FolderIcon% ;if the foldericon exist,
Menu,Browse,Icon,%A_LoopFileName%,%FolderIcon%,1,24 ; use it
else Menu,Browse,Icon,%A_LoopFileName%,shell32.dll,4,24 ;if Foldericon failed , use default
}
else Menu,Browse,Icon,%A_LoopFileName%,shell32.dll,4,24 ;there is no Foldericon, use default
}
else if A_LoopFileName contains .
{
if A_LoopFileExt in exe,ico
Menu,Browse,Icon,%A_LoopFileName%,%A_LoopFileLongPath%,1,24
else {
RegRead,Assoc,HKEY_CLASSES_ROOT,% "." A_LoopFileExt
if ! errorlevel
{
RegRead,Icon,HKEY_CLASSES_ROOT,%Assoc%\DefaultIcon
if ! errorlevel
{
StringSplit, icon,Icon,`,
if ! icon2
icon2:="1"
GetFullName( icon1 )
Menu,Browse,Icon,%A_LoopFileName%,%icon1%,%icon2%,24
; msgbox,%icon%
}
}
}
}
else Menu,Browse,Icon,%A_LoopFileName%,Icons\files.ico,1,24
}
SetTimer,ShowMenuBrowse,-1 ; Show the menu in a new thread and let this thread finish, to avoid #MaxThreads limit.
return
}
BrowseBack:
StringGetPos, l, Browse1,\,R,1 ;get previous directory
; msgbox 1 %l%-%browse1%
if ! errorlevel ; if no error the previous directory is posible
Browse1:=SubStr(Browse1,1,l+1),CreateMenuSingleFolder(Browse1) ;go 1 level back, Recreate themenu
else { ;if there was a error it meens we are at root eg c:
; msgbox %Browse1%
Menu,Browse,add ; Add the menu to avoid error when deleting a nonexisting one
menu,Browse,delete ; Delete the previous menu
Menu,Browse,add,Deze Computer,FakeSub ; Add the item for this computer
Menu,Browse,Disable,Deze Computer ; and make it unklikkable
browse0=1
browse1=
Loop 26 ;loop all drives
{
drv:=Chr(A_Index+64) ":"
ifExist,% drv "\" ;check if the drive exists
{
browse0+=1
browse%browse0%:=drv
Menu,Browse,Add,%drv%,BrowseMenuClicked
IniRead,DriveIcon,% drv "\autorun.inf",autorun,Icon,0 ;Read the driveIcon if posible
if DriveIcon
{
if (SubStr(DriveIcon, 1 , 1)="\") ;if 1 char = \ set the var from the root
DriveIcon:=drv DriveIcon
else if (SubStr(DriveIcon, 1 , 2)=".\") ; if first 2 chars are .\ , replace .\ with X:\ where X is the drive
StringReplace,DriveIcon,DriveIcon,.\,%drv%\,1
else if (SubStr(DriveIcon, 1 , 3)="..\") ; if first 2 chars are ..\ , thats imposible for a drive
msgbox,..\???? not Posible for %A_LoopFileLongPath%\Desktop.ini .ShellClassInfo IconFile=%DriveIcon%
else ifExist,% drv "\" DriveIcon ; if given disk.ico , check if exist X:\disk.ico
DriveIcon:=drv "\" DriveIcon
ifExist,%DriveIcon% ; Final check to see all is ok
Menu,Browse,Icon,%drv%,%DriveIcon%,,32 ;add the icon to the menu
else Menu,Browse,Icon,%drv%,icons\Default.ico,,32 ;if driveicon failed , use default
}
else Menu,Browse,Icon,%drv%,icons\Default.ico,,32 ;if there is no driveicon, use default
}
}
SetTimer,ShowMenuBrowse,-1 ; Show the menu in a new thread and let this thread finish, to avoid #MaxThreads limit.
}
return
FakeSub:
return
BrowseMenuClicked:
if !InStr(FileExist(Browse1 Browse%A_ThisMenuItemPos%), "D") ;check if you clicked a file
run % Browse1 Browse%A_ThisMenuItemPos%
else {
Browse1:=Browse1 Browse%A_ThisMenuItemPos% "\"
CreateMenuSingleFolder(Browse1)
}
; msgbox %Cdir%%A_ThisMenuItem%
return
BrowseMenu:
Browse1:= exedrive "\"
CreateMenuSingleFolder(Browse1)
return
GetFullName( fn ) {
static buf, i
if !i
i := VarSetCapacity(buf, 512)
DllCall("GetFullPathNameA", "str", fn, "uint", 512, "str", buf, "str*", 0)
return buf
}
ShowMenuBrowse:
Menu,Browse,Show,0,0
return
anny comments please, thx
hope someone can use this.
todo:
still working on comments,
and retrieving fileicons from the registry (done)
dont know if this is the place to post it.
is there a place for ahk_L scripts?
ps: is there a way to scroll in a menu?
edit: fixed menufailure,thx Lexikos