I am stuck at how to access the menu item
My menu has 5 items, the first one will have 5 subitems, and I am unable to access the subitems
CMenu* submenu=menu.GetSubMenu(0);
ASSERT(submenu->GetSafeHMenu()); // This line throws exception
Printable View
I am stuck at how to access the menu item
My menu has 5 items, the first one will have 5 subitems, and I am unable to access the subitems
CMenu* submenu=menu.GetSubMenu(0);
ASSERT(submenu->GetSafeHMenu()); // This line throws exception
- What exception?
- Where is this code called from?
- If your CMenu class is a MFC one, then you should probably have posted this question in the Visual C++ Programming Forum
somebody please help me
here is the code
Code:CString OnGetClick()
{
CMenu* submenu=menu.GetSubMenu(0);
ASSERT(submenu);
ASSERT(::ismenu(submenu->GetSafeHMenu()); // This line throws exception
CString str;
submenu->GetMenuString(1,str,NF_BYPOSITION);
return str;
}
1.It is IsMenu Api function
2.that code is actually from a on-command-range message map function
Code:
void OnPickItem(UINT nItem)
{
CMenu* submenu=menu.GetSubMenu(0);
ASSERT(submenu);
ASSERT(::IsMenu(submenu->GetSafeHMenu()); // This line throws exception
submenu->CheckMenuRadioItem(ID_APP1, ID_APP7, nItem, MF_BYCOMMAND);
}
[ moved thread ]
I just redo an old program for fun,
I have a dialog, that when rightclicking on it will show me a popup menu, which includes
File
..Click File 1
..Click File 2
..Click File 3
..Click File 4
..Click File 5
Exit
Each of the |Click File i" Is defined as ID_APP1,....ID_APP5
in the message map, there I define
ON_COMMAND-RANGE(ID_APP1, ID_APP5, &Func)
and there I use the above function but when I run the application, I got an assertion failure right at that line during the debugging,
That isn't a valid menu handle while the previous line passes the ASSERT.
:(
Please help me till the end, I don't want to stop it right now, very urgent help SMS SMS SMS
Exception only shows up after I pick one of those "Click File i", this means menu is valid
If I eliminate that OnPickItem from the program, things are fine
TuringMachine. I have to tell you it's frustrating for the 'regular' folks here that do most of the answering, that when they ask direct questions the original poster doesn't answer them.
It would make it much easier for us to help you, if you answered the questions that are asked. Sometimes, the questions make not seem to be related, but the person trying to help usually asks them to help narrow down the problem.
Also, when ask to post the code - post the code. Giving a description of what you think the code is isn't going to help us (help you). We want to see the actual code.
At any rate, why do you need to get the submenu? You generally should be able to do what you need with OnCommandRange or OnUpdateCommandUI.