Re: EnableMenuItem problem
Try to enable/disable those menu item trough message map, just like this:
Code:
BEGIN_MESSAGE_MAP(CYourView, CListView)
ON_UPDATE_COMMAND_UI(ID_MENUID, OnUpdateItem)
END_MESSAGE_MAP()
Re: EnableMenuItem problem
I have been trying to do this
Code:
BEGIN_MESSAGE_MAP(….)
ON_UPDATE_COMMAND_UI(ID_MENUID, OnUpdateShowResults)
void CAppDoc::OnUpdateShowResults(CCmdUI* pCmdUI)
{
pCmdUI->Enable(FALSE);
}
But I can’t find the correct code way to issue the OnUpdateShowResults() command inside the code.
But the following generates an exception.
Exception thrown: read access violation.
pCmdUI was nullptr
OnUpdateShowResults(FALSE);
Re: EnableMenuItem problem
Are you calling the handler OnUpdateShowResults(FALSE); directly? If so, you shouldn't be calling this directly because the framework will call this for you since you have added an ON_COMMAND_UPDATE_UI map entry. Put a breakpoint inside the handler to make sure it is getting called.
Re: EnableMenuItem problem
[When posting code, please use code tags. Go Advanced, select the formatted code and click '#'].
Cheers!
Re: EnableMenuItem problem
Quote:
Originally Posted by
Arjay
Are you calling the handler OnUpdateShowResults(FALSE); directly? If so, you shouldn't be calling this directly because the framework will call this for you since you have added an ON_COMMAND_UPDATE_UI map entry. Put a breakpoint inside the handler to make sure it is getting called.
The whole point is for the program to be able to disable/enable a drop-down menu item directly without user intervention.
For which reason I was trying unsuccessfully to do this thru the CMenu class. Please see my opening post to this thread.
Per suggestion by mesajflaviu, I began trying to accomplish this thru the message map and by calling the handler directly.
I had placed a breakpoint at the handler and the read access violation occurs at:
Code:
pCmdUI->Enable(FALSE);
thank you...
Re: EnableMenuItem problem
See Arjay's post. Don't call the handler directly. The framework will call it when it needs to.
Re: EnableMenuItem problem
The only way to call the handler INDIRECTLY is for the user to click on the menu item.
But as I have been trying to explain, that is what I am trying to prevent to begin with by disabling it programatically.
I am back to square one. There may be a way to get the CMenu - EnableMenuItem to work.
Re: EnableMenuItem problem
Quote:
Originally Posted by
robertzp
The only way to call the handler INDIRECTLY is for the user to click on the menu item.
But as I have been trying to explain, that is what I am trying to prevent to begin with by disabling it programatically.
I am back to square one. There may be a way to get the CMenu - EnableMenuItem to work.
You are coding it wrong; otherwise, your update ui handler would get called as the menu item is getting displayed and the menu item would be disabled.
Oh, and I get that you think no one UNDERSTANDS your problem even if a few of us answering have programmed in MFC for 20+ years.
Re: EnableMenuItem problem
If you want to enable / disable that menu item programmatically then you only made a condition inside your UpdateMenu handler ... something like this:
Code:
void CAppDoc::OnUpdateShowResults(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bCond);
}
and somewhere in your app:
Code:
m_bCond = TRUE // or FALSE;
and framwork will do the job :)
Re: EnableMenuItem problem
Quote:
Originally Posted by
mesajflaviu
If you want to enable / disable that menu item programmatically then you only made a condition inside your UpdateMenu handler ... something like this:
Code:
void CAppDoc::OnUpdateShowResults(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bCond);
}
and somewhere in your app:
Code:
m_bCond = TRUE // or FALSE;
and framework will do the job :)
My apologies to all.
I made a mistake in coding the message handler. The menu items are now being enabled / disabled programatically.
thanks for your time.
Re: EnableMenuItem problem
Zip up a small project that shows the reproductive and post it here.