How to get the currently focused menu item ID?
I want to display info when my mouse cursor is on an ite开发者_StackOverflowm in my menu by using SendMessage() to my statusbar. How do i get the current menu item ID ? I suppose they use same ID's as my Visual Studio shows in the menu editor.
I found these on msdn but none of them seems to serve my needs:
WM_COMMAND
WM_CONTEXTMENU
WM_ENTERMENULOOP
WM_EXITMENULOOP
WM_GETTITLEBARINFOEX
WM_MENUCOMMAND
WM_MENUDRAG
WM_MENUGETOBJECT
WM_MENURBUTTONUP
WM_NEXTMENU
WM_UNINITMENUPOPUP
While the user is moving around the menu you get WM_MENUSELECT messages. LOWORD(lParam)
will be the id of the menu item unless what is currently being selected is a popup rather than an item.
so your code looks something like this
case WM_MENUSELECT
{
HMENU hmenu = (HMENU) lParam;
UINT idItem = (UINT) LOWORD(wParam);
UINT flags = (UINT) HIWORD(wParam);
if (flags & MF_POPUP)
{
// idItem is actually a popup index
HMENU hSubMenu = GetSubMenu(hmenu, idItem);
idItem = 0; // assign an id to the menu, or just set to 0 for no output
}
// show menu info on status bar for idItem
SendMessage(hwndStatbar, ..., idItem, ...);
}
Have you tried using..
GetFocus();
I think that returns a pointer to the control if I remember correctly.
(maybe not a complete answer, but) Can't you use use strings in the STRINGTABLE section of the resources ?
for example, for your menu ID:
MENUITEM "Your Menu Item...", IDM_YOUR_MENU_ITEM
in the STRINGTABLE
STRINGTABLE
BEGIN
IDM_ALL_SURFACE_PROFILE_FEATURES "Message1\nMessage2"
END
If memory serves me well, the first part of the string will be the text displayed in the statusbar.
Max.
精彩评论