#NoTrayIcon ;#ErrorStdOut SplitPath A_ScriptFullPath, null, IniDir, null, IniFile, null IniFile = %IniDir%\%IniFile%.ini IfNotExist %IniFile% { MsgBox Could not find %IniFile%. ExitApp } ProcessMenu("Menu") Menu Menu, Show Exit SplitFirst(ByRef OutLeft, ByRef OutRight, InpText, InpSep) { StringGetPos SepPos, InpText, %InpSep% If (SepPos >= 0) { StringLeft OutLeft, InpText, %SepPos% RemChars := StrLen(InpText)-SepPos-1 StringRight OutRight, InpText, %RemChars% } Else { OutLeft := InpText OutRight := "" } } ProcessMenu(Menu) { global IniFile IniRead MenuTitle, %IniFile%, %Menu%, Title If (MenuTitle <> "ERROR") { Menu %Menu%, Add, %MenuTitle%, AboutBox Menu %Menu%, Default, %MenuTitle% ; Menu %Menu%, Disable, %MenuTitle% Menu %Menu%, Add } IniRead Count, %IniFile%, %Menu%, MaxItem, 0 Loop %Count% { IniRead, CurItem, %IniFile%, %Menu%, %A_Index% If (CurItem = "-") Menu %Menu%, Add Else If (CurItem <> "ERROR") { SplitFirst(CurID, CurTitle, CurItem, "|") If (CurTitle = "") CurTitle := CurID IniRead IsSub, %IniFile%, %CurID%, MaxItem, 0 If (IsSub = 0) { Menu %Menu%, Add, %CurTitle%, ProcessEvent IniRead CurCmd, %IniFile%, %CurID%, Cmd If (CurCmd = "ERROR") Menu %Menu%, Disable, %CurTitle% } else { ProcessMenu(CurID) Menu %Menu%, Add, %CurTitle%, :%CurID% } IniRead IsChecked, %IniFile%, %CurID%, Checked, 0 If (IsChecked = 1) Menu %Menu%, Check, %CurTitle% } } Return } ProcessEvent: IniRead Count, %IniFile%, %A_ThisMenu%, MaxItem, 0 Loop %Count% { IniRead, CurItem, %IniFile%, %A_ThisMenu%, %A_Index% If (CurItem <> "ERROR") { SplitFirst(CurID, CurTitle, CurItem, "|") If (CurTitle = "") CurTitle := CurID If (CurTitle = A_ThisMenuItem) { IniRead Cmd, %IniFile%, %CurID%, Cmd If (Cmd <> "ERROR") { empty := "" IniRead TargDir, %IniFile%, %CurID%, StartPath, %empty% IniRead StartMode, %IniFile%, %CurID%, StartMode, %empty% Loop 9 { CurPar := %A_Index% StringReplace Cmd, Cmd, `%%A_Index%, %CurPar% } Run %Cmd%, %TargDir%, %StartMode%, PID } } } } Return AboutBox: MsgBox 4160, About ClickMenu..., ClickMenu shows a popup menu with entries read from an INI file and launches the selected program upon click.`n`nMade in 2005 by Markus Birth <mbirth at webwriters.de> Return
a sample .ini file looks like this:
[Menu] ;Maximum number to parse, starting at 1 ;Empty values are ignored. MaxItem=10 Title=EXE compression ; Entries are like: ; <no>=<section>|<menu title> ; <no>=- <=== separator 1=UPX|UPX 1.25w 2=UPXB|UPX 1.93 BETA 3=- 9=MEW|MEW11 SE 1.1 (Compress only) [UPX] MaxItem=2 ; (set following to 1 to show a checkmark in front of menu entry) Checked=0 1=UPXC|Compress 2=UPXD|Decompress [UPXB] MaxItem=2 ; (set following to 1 to show a checkmark in front of menu entry) Checked=0 1=UPXBC|Compress 2=UPXBD|Decompress [UPXC] Cmd="c:\program files\upx.exe" --best --crp-ms=524288 %1 ; (set following to 1 to show a checkmark in front of menu entry) Checked=0 ; (omit or leave empty following to start in current path) StartPath= ; StartMode=(Max|Min|Hide) ; (omit or leave empty following to start normally) StartMode= [UPXD] Cmd="c:\program files\upx.exe" -d %1 [UPXBC] Cmd="c:\program files\upx_beta.exe" --best --crp-ms=524288 %1 [UPXBD] Cmd="c:\program files\upx_beta.exe" -d %1 [MEW] Cmd="C:\Program Files\mew11.exe" %1 -backup -lzma_special
(%1 in those Cmd=lines is replaced by the first parameter of the script. This works up to %9 (for the ninth parameter) for now.)
NOTE: The main menu displayed is what is specified in the [Menu]-section. All other sections can have any name.
Cheers,
-mARKUS
(2005-10-04 Added AboutBox when clicking on a menu heading.)