 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
mbirth
Joined: 03 Oct 2005 Posts: 40 Location: DE, Berlin
|
Posted: Mon Oct 03, 2005 9:13 pm Post subject: Show PopupMenu with programs to launch |
|
|
I made this to extend the functionality of the buttonbar in Total Commander or the Windows QuickLaunch toolbar. It shows a popup menu with a list of programs and executes the selected command upon click. Nothing more. This way you can have one button doing several things. Configuration is read from an INI-file.
| Code: | #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:
| Code: | [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.)
Last edited by mbirth on Tue Oct 04, 2005 7:57 am; edited 1 time in total |
|
| Back to top |
|
 |
Rabiator
Joined: 17 Apr 2005 Posts: 270 Location: Sauerland
|
Posted: Mon Oct 03, 2005 10:24 pm Post subject: |
|
|
Marvellous! Especially the interesting way of building menues recursively!  |
|
| Back to top |
|
 |
tomzi Guest
|
Posted: Tue Jan 24, 2006 2:48 pm Post subject: how to modify? |
|
|
Hi. First I must say that a new in AHK and at programming ... well ... I suck
I found this script very usefull. I modified .INI file so that not an .EXE would be executed, but a script that copies a selected word from MS Word to dictionary. But ... nothing happened. What did I do wrong? Here is part of .INI file - main program I left as it was:
| Code: |
[English]
Cmd= ; Without this line all menu items are disabled - but I don't know the meaning
Clipboard = ; Clears Clipboard
Send ^c ; Copies to Clipboard
IfWinExist, English dictionary
{
WinActivate
Send ^v ; Paste from Clipboard
}
else
{
Run, C:\DICT\DICT.EXE ; Runs dictionary
WinWait, English dictionary
WinActivate
Send ^v ; Paste from Clipboard
}
Return
|
This is only one item in the menu, but I would like to have more of them - they would all look simmilar (actually - I would copy to different dictionaries in same fashion). |
|
| Back to top |
|
 |
BoBo Guest
|
Posted: Tue Jan 24, 2006 3:28 pm Post subject: |
|
|
| This dict didn't offer an import option ? What's the format of the dict file (which keeps the entries you c&p) ? |
|
| Back to top |
|
 |
tomzi Guest
|
Posted: Tue Jan 24, 2006 4:01 pm Post subject: |
|
|
| BoBo wrote: | | This dict didn't offer an import option ? What's the format of the dict file (which keeps the entries you c&p) ? |
Sorry if I wasn't clear.
Well - "Dict.exe" (just a "dummy" name) is only executable of some dictionary program. Immediately after it is oppened - has user option to input a word, and program at the same time displays explanation - without pressing Enter. Focus is set on input filed immediately after program is ran.
This is why I can simply copy a word -> switch to (or run) dictionary -> and paste to input field. I have more dictionaries (english, german ..) which are all from same vendor and all operate in the same way.
This all works perfect if I use simple hotkey - let's say "F2::", "F3::" etc. So nothing is wrong with:
| Code: |
Clipboard =
Send ^c
IfWinExist, English dictionary
{
WinActivate
Send ^v
}
else
{
Run, C:\DICT\DICT.EXE
WinWait, English dictionary
WinActivate
Send ^v
}
Return
|
I just don't know how to implement this into .INI file. Or maybe - how to modify it to work instead of pure run command such as:
| Code: |
Cmd="c:\program files\upx.exe" -d %1
|
, which is in mbirth's example. |
|
| Back to top |
|
 |
tomzi
Joined: 25 Jan 2006 Posts: 2 Location: Slovenia
|
Posted: Thu Jan 26, 2006 6:03 am Post subject: ?? |
|
|
Has no one any idea?  |
|
| Back to top |
|
 |
mbirth
Joined: 03 Oct 2005 Posts: 40 Location: DE, Berlin
|
Posted: Thu Jan 26, 2006 7:31 am Post subject: |
|
|
The thing is: The INI-file just contains configuration information. It was never meant to hold AHK-sourcecode.
To realize your idea, you would have to introduce three new options in the INI file:
| Code: | [dict]
Cmd=dict.exe
WindowName=English dictionary
SendBefore=^c
SendAfter=^v |
And the script should be changed like this around the Run-command:
| Code: | IniRead TargDir, %IniFile%, %CurID%, StartPath, %empty%
IniRead StartMode, %IniFile%, %CurID%, StartMode, %empty%
IniRead WindowName, %IniFile%, %CurID%, WindowName, %empty%
IniRead SendBefore, %IniFile%, %CurID%, SendBefore, %empty%
IniRead SendAfter, %IniFile%, %CurID%, SendAfter, %empty%
Loop 9
{
CurPar := %A_Index%
StringReplace Cmd, Cmd, `%%A_Index%, %CurPar%
}
Send %SendBefore%
If (WindowName <> "" and WinExist(WindowName) <> 0)
{
WinActivate %WindowName%
}
else
{
Run %Cmd%, %TargDir%, %StartMode%, PID
}
Send %SendAfter%
}
} |
This code is untested, but you should get the idea.
Cheers,
-mARKUS |
|
| Back to top |
|
 |
tomzi
Joined: 25 Jan 2006 Posts: 2 Location: Slovenia
|
Posted: Thu Jan 26, 2006 9:17 pm Post subject: Success |
|
|
Eureka!
I found different popup menus on this forum - one is from Rajat - but mbirth - yours is really neat. It can be easily modified. And it is the only one that looks like normal Windows menu & also each line is highlighted when mouse cursor is over it - nice.
I used exactly the same INI structure as you suggested, but I made little modification in Run command section:
| Code: |
IniRead TargDir, %IniFile%, %CurID%, StartPath, %empty%
IniRead StartMode, %IniFile%, %CurID%, StartMode, %empty%
IniRead WindowName, %IniFile%, %CurID%, WindowName, %empty%
IniRead SendBefore, %IniFile%, %CurID%, SendBefore, %empty%
IniRead SendAfter, %IniFile%, %CurID%, SendAfter, %empty%
Loop 9
{
CurPar := %A_Index%
StringReplace Cmd, Cmd, `%%A_Index%, %CurPar%
}
Send %SendBefore%
If (WindowName <> "" and WinExist(WindowName) <> 0)
{
WinActivate %WindowName%
}
else
{
Run %Cmd%, %TargDir%, %StartMode%, PID
-> WinWait %WindowName% ;waits for program window
-> WinActivate %WindowName% ;program window is activated
}
Send %SendAfter%
}
}
}
|
That's all.
Thank you. And:
Dein post hat mir richtig viel geholfen. Ich verstehe jetzt besser wie AHK code sieht aus. (English: Your post helped me a lot. I understand now better the AHK code structure) |
|
| Back to top |
|
 |
jchristl
Joined: 13 Jan 2006 Posts: 26
|
Posted: Fri Feb 17, 2006 3:56 pm Post subject: Great |
|
|
This script is awesome.
Just one question: Why is it slower when clicked on with the mouse, whereas if called by hitting enter, or calling it with a hotkey, it runs faster? |
|
| Back to top |
|
 |
mbirth
Joined: 03 Oct 2005 Posts: 40 Location: DE, Berlin
|
Posted: Fri Feb 17, 2006 5:02 pm Post subject: Re: Great |
|
|
| jchristl wrote: | | Just one question: Why is it slower when clicked on with the mouse, whereas if called by hitting enter, or calling it with a hotkey, it runs faster? |
I don't know. Maybe it's a strange thing with Windows or so....
Cheers,
-mARKUS |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|