PDA

View Full Version : Adding a submenu


sws
04-29-2008, 08:37 AM
Xenakios, this is for you. :)

Let's say you want to add a submenu to the end of the REAPER Edit menu that gives you a list the commands you've defined in your plugin. In your entry point function, after you've defined all of your command accelerators and IDs, do this:


HMENU hSubMenu = CreatePopupMenu();
MENUITEMINFO mi={sizeof(MENUITEMINFO),};
mi.fMask = MIIM_TYPE | MIIM_ID;
mi.fType = MFT_STRING;

// Add a section like this for each of your commands
mi.wID = my_command_id_1;
mi.dwTypeData = "My command 1";
InsertMenuItem(hSubMenu, 0, TRUE, &mi);

// Here's command #2, make sure to increment InsertMenuItem index
mi.wID = my_command_id_2;
mi.dwTypeData = "My command 2";
InsertMenuItem(hSubMenu, 1, TRUE, &mi);

// add more commands as above, then add it to REAPER

// Index '1' in GetSubMenu returns the 2nd menu, in this case, the "Edit" menu
HMENU hMenu = GetSubMenu(GetMenu(GetMainHwnd()),1);
mi.fMask = MIIM_SUBMENU | MIIM_TYPE;
mi.hSubMenu = hSubMenu;
mi.dwTypeData = "My commands"; // Name of submenu
// Add to end of menu with GetMenuItemCount so if Justin adds/subtracts items nothing breaks
InsertMenuItem(hMenu, GetMenuItemCount(hMenu), TRUE, &mi);

Hope this helps!

Xenakios
04-29-2008, 08:39 AM
Heh, ok, thanks for this! :)

I was kind of hoping maybe an additional main menu item, next to "Help", but I think that's maybe too tricky to do... ;)

Anyway, this will do just fine, as most of my new commands are somewhat "editing" related, so they fit nicely to a submenu in the edit-menu...

sws
04-29-2008, 08:44 AM
Hehe, that's easy too, change the last bit of code above to:

HMENU hMenu = GetMenu(GetMainHwnd());
mi.fMask = MIIM_SUBMENU | MIIM_TYPE;
mi.hSubMenu = hSubMenu;
mi.dwTypeData = "My commands";
InsertMenuItem(hMenu, GetMenuItemCount(hMenu)-1, TRUE, &mi);

The differences are GetMenu() instead of GetSubMenu() (to put you on the top menu bar) and GetMenuItemCount-1 (otherwise you're to the right of the HW status "menu").

Deric
04-29-2008, 09:59 AM
Great stuff SWS!

Xenakios
04-29-2008, 04:40 PM
Yes, seems to work :) :

http://stash.reaper.fm/1182/NewMainMenuEntry2.png