TSmooth
November 13th, 2003, 11:53 AM
I have a program which has a menu created in the resource editor consisting of the following top level menus: File, Edit, and Rides. The Rides menu initially contains only a separator bar but during the programs initializaion functions, several menu items are added to it. I need to process these menu items when they are clicked, obviously, but since I do not know the exact number or therefore the ID of the menu items ahead of time, I found that I need to force the menu to generate WM_MENUCOMMAND messages instead of WM_COMMAND messages. I did this using the following code after reading related MSDN information:
HMENU hMenu;
MENUINFO MenuInfo;
BOOL fResult;
hMenu = GetMenu(hwnd);
hMenu = GetSubMenu(hMenu, 2); // Handle to the "Rides" menu
MenuInfo.cbSize = sizeof(MENUINFO);
MenuInfo.dwStyle = MNS_NOTIFYBYPOS;
MenuInfo.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
fResult = SetMenuInfo(hMenu, &MenuInfo);
SetMenuInfo returns success however WM_COMMANDs are still being generated for this menu instead of WM_MENUCOMMAND. I tried this without setting the MIM_APPLYTOSUBMENUS flag as well as the entire piece of code after the new menuitems are already added instead of before. Any help/suggestions would be appreciated. Thanks!
P.S. If i comment out the GetSubMenu() line then it works for all menus, they all generate WM_MENUCOMMAND, but i need it to work for the "Rides" menu only.
HMENU hMenu;
MENUINFO MenuInfo;
BOOL fResult;
hMenu = GetMenu(hwnd);
hMenu = GetSubMenu(hMenu, 2); // Handle to the "Rides" menu
MenuInfo.cbSize = sizeof(MENUINFO);
MenuInfo.dwStyle = MNS_NOTIFYBYPOS;
MenuInfo.fMask = MIM_STYLE | MIM_APPLYTOSUBMENUS;
fResult = SetMenuInfo(hMenu, &MenuInfo);
SetMenuInfo returns success however WM_COMMANDs are still being generated for this menu instead of WM_MENUCOMMAND. I tried this without setting the MIM_APPLYTOSUBMENUS flag as well as the entire piece of code after the new menuitems are already added instead of before. Any help/suggestions would be appreciated. Thanks!
P.S. If i comment out the GetSubMenu() line then it works for all menus, they all generate WM_MENUCOMMAND, but i need it to work for the "Rides" menu only.