#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=QuickLaunch.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include #include "ModernMenuRaw.au3" Opt("GUIOnEventMode", 1) Opt("TrayOnEventMode",1) Opt("TrayMenuMode",3) ;The following IF statement allows the compiled script to be started twice only ;if it's started with "/restart" parameter, otherwise there can be ;only one instance of it. If Not $CMDLINE[0] Then If UBound(ProcessList(@ScriptName)) > 2 Then Exit ElseIf $CMDLINE[1] <> "/restart" Then Exit EndIf ;Add hotkey CTRL+ALT+X to exit and CTRL+ALT+R to restart HotKeySet("^!x", "MyExit") HotKeySet("^!r", "_Restart") ;Get the QuickLaunch folder from the INI file $INI=StringTrimRight(@ScriptName,4)&".ini" GLOBAL $QuickLaunchFolder = IniRead($INI, "Settings", "QLFolder", "D:\My Documents\QuickAccess") ;Create an array to store the control IDs and the path to the file GLOBAL $aControlIDs[1][3] $aControlIDs[0][0]=0 ;Create a 5px x 5px GUI at the top left corner of the screen and populate the menu GLOBAL $GUI=GUICreate("QuickLaunch",5,5,0,0,$WS_POPUP,BitOr($WS_EX_TOPMOST,$WS_EX_TOOLWINDOW)) GLOBAL $idMenu = GUICtrlCreateMenu("QuickLaunch") PopulateMenu($QuickLaunchFolder, $idMenu) GUISetState(@SW_SHOW,$GUI) ;Create the tray menu $_RESTART=TrayCreateItem("Restart (CTRL+ALT+R)") TrayItemSetOnEvent($_RESTART,"_Restart") TrayCreateItem("") $_EXIT=TrayCreateItem("Exit (CTRL+ALT+X)") TrayItemSetOnEvent($_EXIT,"MyExit") ;Check if the mouse is in the top left corner and click to open the menu While 1 Sleep(500) $X=MouseGetPos(0) $Y=MouseGetPos(1) If $X<3 And $Y<3 Then MouseClick("left", 0, 0, 1, 0) EndIf WEnd ;------------------------------------------------------ ;Populate the menu with the contents of the QuickLaunch folder Func PopulateMenu($Dir, $Menu) ; Ensure the folder exists If Not FileExists($Dir) Then MsgBox(48, "QuickLaunch", "The folder: " & $Dir & " does not exist.") Return EndIf ;Step1: Loop through teh contents of the folder and pocess only the folders Local $search = FileFindFirstFile($Dir & "\*.*") If $search = -1 Then ;Return if the folder is empty Return EndIf While 1 Local $sFile = FileFindNextFile($search) If @error Then ExitLoop If @extended = 1 Then $Detail = FileGetShortcut($Dir & "\" & $sFile) $SubMenu = GUICtrlCreateMenu($sFile,$Menu) ;Recursively call the function to populate the sub menu PopulateMenu($Dir & "\" & $sFile, $SubMenu) EndIf WEnd FileClose($search) ;Step2: Loop through files and pocess only the shortcuts (.lnk files) Local $search = FileFindFirstFile($Dir & "\*.lnk") If $search = -1 Then Return EndIf While 1 Local $sFile = FileFindNextFile($search) If @error Then ExitLoop If @extended = 0 Then ;Skip the hidden fies If StringInStr(FileGetAttrib($Dir & "\" & $sFile), "H") Then ContinueLoop ;Get the details of the shortcut $Detail = FileGetShortcut($Dir & "\" & $sFile) local $aControlID[1][3] ;Create the menu item If IsArray($Detail) Then If $Detail[4] Then $MenuItem = _GUICtrlCreateODMenuItem(TrimExt($sFile), $Menu, $Detail[4], $Detail[5]) Else $MenuItem = _GUICtrlCreateODMenuItem(TrimExt($sFile), $Menu, $Detail[0], $Detail[5]) EndIf Else $MenuItem = GUICtrlCreateMenuItem(TrimExt($sFile),$Menu) EndIf ;Set the event handler for the menu item GUICtrlSetOnEvent(-1, "RunProg") ;Add the control ID and the path to the file to the array $aControlID[0][0] = $MenuItem $aControlID[0][1] = $Dir $aControlID[0][2] = $sFile $res = _ArrayAdd($aControlIDs, $aControlID) If $res <> 0 Then $aControlIDs[0][0] += 1 Else MsgBox(48, "QuickLaunch", "Error adding control ID to array: " & @error) EndIf EndIf WEnd FileClose($search) EndFunc ;------------------------------------------------------ ;Run the selectec program Func RunProg() ;Loop through the array to find the path to the file For $i=1 to $aControlIDs[0][0]-1 If $aControlIDs[$i][0]=@GUI_CTRLID Then ShellExecute($aControlIDs[$i][1] & "\" & $aControlIDs[$i][2]) Return EndIf Next EndFunc ;------------------------------------------------------ Func TrimExt($sFile) Return StringRegExpReplace($sFile, "\.[^.]*$", "") EndFunc ;------------------------------------------------------ ;Restart the program Func _Restart() If @Compiled Then Run(@ScriptFullPath& " /restart") exit Else MsgBox(48,"QuickLaunch","The Restart works only when the script is a compiled executable.") EndIf EndFunc ;------------------------------------------------------ ;Exit the program Func MyExit() $answer = MsgBox(36,"QuickLaunch","Are you sure you want to exit QuickLaunch?") If $answer = 6 Then GUIDelete($GUI) Exit EndIf EndFunc