Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EnableMenuItem(...) not working?!

Status
Not open for further replies.

gorgor

Programmer
Aug 15, 2002
164
0
0
US
I have a pointer to a CMenu object that I created and the menu is being displayed as a context menu. I want to disable (gray) one of the menu items and I can't get it to "gray out". I know my pointer is valid because I can get use CheckMenuItem(...) perfectly fine. Has anyone come across this problem? Any other way to get it working? Here's my code...

m_pPopMenu->EnableMenuItem(IDM_PROPERTIES, MF_GRAYED); //Not working!
m_pPopMenu->CheckMenuItem(IDM_OTHERITEM, MF_CHECKED); //This works fine!

CMenu* pContextMenu = m_pPopMenu->GetSubMenu(0);
pContextMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);

Does it matter that I created the CMenu object's resource at compile time instead of at runtime? (I'm using MFC and MSVC++ .NET).

Thanks in advance.
 
I think you should
m_pPopMenu->EnableMenuItem(IDM_PROPERTIES, TRUE or FALSE there);

Ion Filipski
1c.bmp
 
That didn't do it. It still isn't disabled or grayed.
 
The second parameter can be a combination of MF_DISABLED, MF_ENABLED, or MF_GRAYED, with MF_BYCOMMAND or MF_BYPOSITION. These values can be combined by using the bitwise OR operator (operator |).

Ion Filipski
1c.bmp
 
That's what MSDN says. I've tried all combinations of 'UINT nEnable' and none are working. I can only get CheckMenuItem() working. This just doesn't seem right.
 
it seems you don't combine flags in a right way, or you use a wrong menu item id.

Ion Filipski
1c.bmp
 
Hi,
I had a similar problem. Did you try using the UpDateCommandUI()?

 
mpsoutine,

UpDateCommandUI() is not a member of CMenu and there is no description of it in MSDN. Could you clarify and perhaps show a small example how to use it?

Thanks!
 
Hi G,

If you go to class wizard/click on the menu object ID/and look in the Message Window. You will see Command and UpdateCommandUI()

I used this function to enable two menu items after I clicked an item in a list control.

Hope this code helps.

void CBirthRecordView::OnUpdateEditPerson(CCmdUI* pCmdUI)
{
CListCtrl* pList;
pList = &m_lcPerson;

int rtValue = m_lcPerson.GetNextItem(-1,LVNI_SELECTED);

if(rtValue != -1)
pCmdUI->Enable(true);
else
pCmdUI->Enable(false);



}
 
I'll look into mpsoutine's suggestion. I have simplified my code to its bare bones and the MF_GRAY still isn't working. The code can't get any simpler than this. Can anyone see anything that might be causing it not to work??

m_pPopMenu = new CMenu;
m_pPopMenu->CreatePopupMenu();

BOOL result = m_pPopMenu->AppendMenu(MF_STRING, 5000, "Delete");
result = m_pPopMenu->AppendMenu(MF_STRING, 5010, "Properties");
UINT nState = m_pPopMenu->EnableMenuItem(5000, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED); //Not working!
nState = m_pPopMenu->EnableMenuItem(5010, MF_BYCOMMAND | MF_GRAYED | MF_DISABLED); //Not working!
nState = m_pPinPopMenu->CheckMenuItem(5010, MF_CHECKED); //This works fine!
m_pPopMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 0, 0, this);
 
oops...

nState = m_pPinPopMenu->CheckMenuItem(5010, MF_CHECKED); //This works fine!

should read:

nState = m_pPopMenu->CheckMenuItem(5010, MF_CHECKED); //This works fine!
 
mpsoutine:

I found your question that you posted on the same topic. I fiddled with my code and it works great now. I need to dig a little deeper to understand it, but at least it's working now. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top