Click to See Complete Forum and Search --> : EnableMenuItem() - Need Help


John Hagen
April 15th, 1999, 10:26 AM
I am trying to do something as simple as changing a submenu item on the IDR_MAINFRAME menu from Enabled to grayed. I contuiue to have problems of stupid proportions and have just about given up. Can someone give me an idea as to how to do this? If I were to create a MFC app, from the app wizard, no frills or thrills, can you tell me where and what code I need to add to enable/disable (gray it out) any command of your choosing on the FILE menu? If you could post the segment of code, I would be very greatful.

Thanks!

John Hagen

Paul McKenzie
April 15th, 1999, 11:43 AM
Check out ON_UPDATE_COMMAND_UI in the message map section. Class wizard gives you the option of including this message in the message map. The implementation is usually this (assume ID_FILE_TESTING is my menu ID):

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_UPDATE_COMMAND_UI(ID_FILE_TESTING, OnUpdateFileTesting)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

...
BOOL MyEnableValue; // Used in my app to determine if menu item should be enabled
...

void CMainFrame::OnUpdateFileTesting(CCmdUI* pCmdUI)
{
// Set Menu to Enabled /Disabled depending on MyEnableValue setting
pCmdUI->Enable(MyEnableValue);
}

Regards,

Paul McKenzie

yash
April 15th, 1999, 12:09 PM
Hi ,

1) In MainFrame.cpp set bAutoMenuEnable to false as below.

CMainFrame::CMainFrame()
{

m_bAutoMenuEnable = FALSE ;
...

}


2) IN ur View class on UpadateCommand enabel or disabel as required :

void CMyView::OnUpdateUtilitiesStatistics(CCmdUI* pCmdUI)
{
if ( pCmdUI->m_pMenu != NULL )
{
CMenu * pm = pCmdUI->m_pMenu ;

if ( !m_Pause )
pm->EnableMenuItem( 0 , MF_BYPOSITION|MF_GRAYED) ;
else
pm->EnableMenuItem( 0 , MF_BYPOSITION|MF_ENABLED) ;
}
}



Hope this helps you.
Good Luck.
Yash.

John Hagen
April 15th, 1999, 02:40 PM
Thanks for your help, Yash. It's now working.

John Hagen
April 15th, 1999, 02:41 PM
Thanks for your help, Paul. It's now working.

michelle5422
May 9th, 2003, 12:35 AM
why i got the error -&gt unidentified??? ehmmm hope u all can help me yah ...thank ur reply nad help