 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
BaldieJr
Joined: 02 Jul 2004 Posts: 23
|
Posted: Tue Jul 06, 2004 9:51 pm Post subject: Dynamic tray menu from ini (was in Scripts forum) |
|
|
Maybe I'm missing something, but I cant seem to loop through an Ini to build a tray menu. Any help would be appreciated.
Ini:
| Code: |
[Menu1]
Name=FirstMenuItem
Path=C:\Path\to\Notepad.exe
[Menu2]
Name=SecondMenuItem
Path=C:\Path\to\Calculator.exe
|
Script:
| Code: |
inifile = conf.ini
Loop
{
IniRead, name, %inifile%, Menu%A_Index%, Name
if name = ERROR
{
break
}
IniRead, path, %inifile%, Menu%A_Index%, Path
menu, tray, add, %name%
%name%:
Run, %path%
}
|
I'm sure I am doing this all wrong. Thanks in advance. |
|
| Back to top |
|
 |
BaldieJr
Joined: 02 Jul 2004 Posts: 23
|
Posted: Wed Jul 07, 2004 2:53 am Post subject: |
|
|
| This is much tougher to crack than I initially thought. Unless I'm overlooking somthing, there appears to be no way to create a label on-the-fly. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jul 07, 2004 4:18 am Post subject: |
|
|
I am using temp and "bridge files" to build or update my menus.
One file with the first menu section ( all menu,mymenu,add,blabla...menu
mymenu,show...)and another file with the second section(labels and
actions).
A Loop,read,"bridge files","temp file" to filter what you want to remove or
to add new items.And Loop,read, "temp files",menu.ahk to build the menu
It is not elegant,but it is working. |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Jul 07, 2004 4:20 am Post subject: |
|
|
| Forgot to mention: Loop,Read...used with FileAppend command |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jul 07, 2004 5:43 am Post subject: |
|
|
| Quote: | | This is much tougher to crack than I initially thought. Unless I'm overlooking somthing, there appears to be no way to create a label on-the-fly. |
Although you can't create labels dynamically, you can use the build-in variables A_ThisMenuItem and A_ThisMenu to determine which menu item the user selected. To make use of this, make all your menu items point to the same label. Then have a series of else-if's to determine what action to take.
In other words, when you add your menu items in a loop, do it this way:
menu, tray, add, %name%, MenuHandler
Then have the MenuHandler label *outside* the loop:
Loop
{
...
}
...
return
MenuHandler:
MsgBox You selected %A_ThisMenuItem% from the menu %A_ThisMenu%.
return |
|
| Back to top |
|
 |
BaldieJr
Joined: 02 Jul 2004 Posts: 23
|
Posted: Wed Jul 07, 2004 7:46 am Post subject: |
|
|
Thanks Chris, that works quite well.
For some reason or other, I misunderstood the docs concerning menus. I did not realize that the menu name did not have to be the same as the label name.
Once this was understood, it became quite easy. Again, thanks a lot!
Example for posterity:
| Code: |
inifile = conf.ini
#Persistent
menu, tray, add, ;sep
Loop
{
IniRead, name, %inifile%, Menu%A_Index%, Name
if name = ERROR
{
break
}
menu, tray, add, %name%, MenuHandler
}
return
MenuHandler:
Loop
{
IniRead, name, %inifile%, Menu%A_Index%, Name
if name = %A_ThisMenuItem%
{
IniRead, path, %inifile%, Menu%A_Index%, Path
break
}
}
Run, %path%
return
|
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Wed Jul 07, 2004 12:52 pm Post subject: |
|
|
| Quote: | | I did not realize that the menu name did not have to be the same as the label name. |
Yes, the docs are not clear enough about this, so I'm adding some material. Thanks for mentioning it. |
|
| 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
|