[MFC] Menu headaches
-
Hi. I'm translating some menu options and I'm running into a problem with it. I have this menu item, which is a popup menu, inside the Edit menu. For setting menu item text, I have made the following function:
ASSERT( pMenu != NULL);
ASSERT( ::IsMenu( pMenu->GetSafeHmenu()) != FALSE);UINT nFlags = pMenu->GetMenuState( nPos, MF_BYPOSITION);
UINT_PTR nNewID = 0;
if( nFlags & MF_POPUP)
{
CMenu *pSubMenu = pMenu->GetSubMenu( nPos);
ASSERT_VALID( pSubMenu);
nNewID = (UINT_PTR)pSubMenu->GetSafeHmenu();
}
else
{
nNewID = pMenu->GetMenuItemID( nPos);
}return (pMenu->ModifyMenu( nPos, nFlags | MF_BYPOSITION, nNewID, inText) != 0);
This function works fine, I've been using the same function to translate some other menu items (I've added an item next to file, edit, etc.). But for some reason these other menu options end up being empty. But when I try to retrieve the text, with GetMenuString, it shows what I entered in the resource... now, what the heck am I doing wrong here??
-
Hi. I'm translating some menu options and I'm running into a problem with it. I have this menu item, which is a popup menu, inside the Edit menu. For setting menu item text, I have made the following function:
ASSERT( pMenu != NULL);
ASSERT( ::IsMenu( pMenu->GetSafeHmenu()) != FALSE);UINT nFlags = pMenu->GetMenuState( nPos, MF_BYPOSITION);
UINT_PTR nNewID = 0;
if( nFlags & MF_POPUP)
{
CMenu *pSubMenu = pMenu->GetSubMenu( nPos);
ASSERT_VALID( pSubMenu);
nNewID = (UINT_PTR)pSubMenu->GetSafeHmenu();
}
else
{
nNewID = pMenu->GetMenuItemID( nPos);
}return (pMenu->ModifyMenu( nPos, nFlags | MF_BYPOSITION, nNewID, inText) != 0);
This function works fine, I've been using the same function to translate some other menu items (I've added an item next to file, edit, etc.). But for some reason these other menu options end up being empty. But when I try to retrieve the text, with GetMenuString, it shows what I entered in the resource... now, what the heck am I doing wrong here??
Not 100% sure what you mean in your question, but do you need to use the
MF_STRING
flag in theModifyMenu
call? Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong? -
Not 100% sure what you mean in your question, but do you need to use the
MF_STRING
flag in theModifyMenu
call? Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?I've tried that too, result is the same. It's a bit of a strange case. I'm basically translating every menu option, and for the top level menus (file, edit, view, etc.) I'm using the function I posted in my original message. The menu items that are there by standard (file, edit, etc.) are done fine, I can change the translation and it would show up differently. However, I've added one extra item called Production, when using the same function as all the others, I end up having an empty menu option. Let me try to get a screenshot online: Picture Between Tools and Window there's an item missing: Production And at the bottom of the picture, I'm obviously missing text... But like I said, if I change the translation for like tools or something, which uses the same function, it does work..:confused:
-
I've tried that too, result is the same. It's a bit of a strange case. I'm basically translating every menu option, and for the top level menus (file, edit, view, etc.) I'm using the function I posted in my original message. The menu items that are there by standard (file, edit, etc.) are done fine, I can change the translation and it would show up differently. However, I've added one extra item called Production, when using the same function as all the others, I end up having an empty menu option. Let me try to get a screenshot online: Picture Between Tools and Window there's an item missing: Production And at the bottom of the picture, I'm obviously missing text... But like I said, if I change the translation for like tools or something, which uses the same function, it does work..:confused:
One possible reason is that as your setting the test of a popup menu item, such items always have an ID of -1 or 0 (I forget which). This means that you may be corrupting the item by setting a new WM_COMMAND ID for the popup menu item to something other than -1/0. Also, are you calling DrawMenuBar() after all your changes to the menu as you should do if you change the visual aspect of a menu item. Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?
-
One possible reason is that as your setting the test of a popup menu item, such items always have an ID of -1 or 0 (I forget which). This means that you may be corrupting the item by setting a new WM_COMMAND ID for the popup menu item to something other than -1/0. Also, are you calling DrawMenuBar() after all your changes to the menu as you should do if you change the visual aspect of a menu item. Roger Allen - Sonork 100.10016 Strong Sad: I am sad I am flying Who is your favorite Strong?
According to MSDN I'm supposed to pass on a menu handle (HMENU) of the popup for any menu items which have the MF_POPUP flag set. I'm not entirely sure what you mean with the new command ID otherwise? I'm not calling DrawMenuBar(), no. I tried that before, but that didn't seem to make any difference. Everything else works without calling it, so it didn't seem necessary. MSDN says I should, but like I said, there's no difference.