Dynamic menus and messages?
-
Hello! I am currently trying to make some dynamic menu, i.e. add menu items to the main menu at runtime. For the command IDs, I've registered a ON_COMMAND_RANGE handler in the message map, to intercept different commands from the menu items. Now I wonder: is it better to use the command IDs starting from WM_USER+X or WM_APP+X ??
-
Hello! I am currently trying to make some dynamic menu, i.e. add menu items to the main menu at runtime. For the command IDs, I've registered a ON_COMMAND_RANGE handler in the message map, to intercept different commands from the menu items. Now I wonder: is it better to use the command IDs starting from WM_USER+X or WM_APP+X ??
What I normally do when given such a requirement is to "block off" a set of contiguous command IDs within resource.h that accommodate for the maximum number of elements in the dynamic menu.
#define ID_DYNAMIC_MENU_START 200
#define ID_DYNAMIC_MENU_RESERVE1 200
#define ID_DYNAMIC_MENU_RESERVE2 201
#define ID_DYNAMIC_MENU_RESERVE3 202
#define ID_DYNAMIC_MENU_RESERVE4 203
#define ID_DYNAMIC_MENU_END 203Notice I have the DYNAMIC_MENU_START and DYNAMIC_MENU_END pointing at the first and last dynamic menu item respectively. I fill in the ones in the middle as we do not want them used by other resources. We can now set the menu range accordingly. Add to the .h
afx_msg void OnDynamicMenu(UINT nID);
Add to the message map
ON_COMMAND_RANGE(ID_DYNAMIC_MENU_START, ID_DYNAMIC_MENU_END, OnDynamicMenu)
Add to the .cpp
void CMyClass::OnDynamicMenu(UINT nID)
{
// nID is the ID of the menu clicked
}Ant. I'm hard, yet soft.
I'm coloured, yet clear.
I'm fruity and sweet.
I'm jelly, what am I? Muse on it further, I shall return! - David Walliams (Little Britain)