Re: [GD-Windows] Unique menu IDs
Brought to you by:
vexxed72
From: Pierre T. <p.t...@wa...> - 2002-10-15 15:33:27
|
> IIRC, the suggested remedy is to allocate a range of IDs that you use > for this purpose and keep track of which ones you're using at the > moment when you need a new one. Ok. It doesn't sound very nice, but I can do that. I have another problem that I still don't know how to solve, even after a couple of hours browsing the MSDN and monitoring menu-related messages. Here's the thing : - I have a windowed app with a standard menu. It's been working for a long time, no problem here. - The app can load some plug-ins. I dynamically add a menu item for each plug, and get back selected plug-in when user clicks on corresponding menu entry. This works, that's the part with the unique IDs I was talking about. - Today I tried to go one step further : now I'd like to add a new sub-menu for each plug, not only a new menu item. The sub-menu is a exposed via a menu handle (HMENU) by each plug. So I modified my old code to take this into account : MENUITEMINFO NewItem; NewItem.cbSize = sizeof(NewItem); NewItem.fMask = MIIM_TYPE|MIIM_STATE|MIIM_ID|MIIM_SUBMENU; NewItem.fType = MFT_STRING; NewItem.fState = MFS_UNCHECKED; NewItem.wID = 36000 + it->GetKernelID(); // NewItem.hSubMenu = null; NewItem.hSubMenu = it->GetSubMenu(); NewItem.hbmpChecked = null; NewItem.hbmpUnchecked = null; NewItem.dwItemData = 0; NewItem.dwTypeData = it->GetName(); NewItem.cch = strlen(it->GetName()); BOOL Status = InsertMenuItem(GetMenu(hWnd), IDM_INTERFACES, FALSE, &NewItem); Comments : - 36000 is an hardcoded number greater than all static menu identifiers already used by the app. - "it" is a plug-in interface - the newly added bits (to handle submenus) are just the MIIM_SUBMENU flag and the hSubMenu member. This works, but I have a little problem : What happened before : - on selection, I was able to catch the "wID" value thanks to the WM_COMMAND message of the app's WindowProc. - from there, I was able to get back the corresponding plug-in interface What's happening now: - on selection, I'm given a menu identifier *from the selected plug-in's submenu*, which should be handled by the plug, not by the app. - unfortunately I don't know how to get the previous "wID", so I don't know what's the selected plug anymore ! Is there a way to get this ID back, somewhere ? Maybe I could change the design and let the plug-ins handle their own menus, with their own window proc. But I'd like to handle it once and for all in the app, so that the plugs don't have to bother with this. Thanks for reading a long post.... Pierre |