Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » how to DISABLE menuitems for a DIALOG based applications? Collapse All
Subject Author Date
Wang Yang Nov 1, 2004 - 5:56 PM

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>


    I have builded a dialog based applications with a top menubar. I want to disable and gray some menuitems (for example, a "saveas..." menuitem ID_SAVEAS) in the menubar when the application start. So I add the following code into the OnInitDialog() function in the dialog’s class:<o:p></o:p>


<o:p> </o:p>


CMenu *pMenu=m_wndMenuBar.GetMenu();<o:p></o:p>


pMenu->EnableMenuItem(ID_SAVEAS,MF_BYCOMMAND | MF_DISABLED | MF_GRAYED);<o:p></o:p>


<o:p> </o:p>


    But when I compile and run the application, the "saveas..." menuitem is still enabled and not grayed. It seems that the above code takes no effect!!! So what I want to ask you is that how to disable or gray menuitems for a DIALOG based applications with Prof-UIS?<o:p></o:p>


<o:p> </o:p>


    Thanks a lot!<o:p></o:p>


<o:p> </o:p>


    Best Regards,<o:p></o:p>


<o:p> </o:p>


    Yang Wang<o:p></o:p>


<o:p> </o:p>


    My email: <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" /><st1:PersonName w:st="on">wy25@mail.bnu.edu.cn</st1:PersonName><o:p></o:p>

Technical Support Nov 2, 2004 - 3:37 AM

Dear Yang,

The CExtMenuControlBar::GetMenu() method is used in Prof-UIS internally so you should not use it. The menu items inside the menu bar are updated via MFC’s command update mechanism, which is based on CCmdUI class. So, you need to add the ID_SAVEAS command update handler to your dialog in which pCmdUI->Enable( FALSE ) should be called to disable the the menu item (command) when needed.

Bjorn Lindahl Feb 11, 2005 - 7:37 AM

Could I do the same thing to temporarely hide menuitems (i.e. check inactive in the properties for a menuitem in resourceview) in some way?

Technical Support Feb 13, 2005 - 7:10 AM

Dear Bjorn,

Unfortunately you cannot use the MFC command updating mechanism for hiding command items in toolbars and menus. It only allows you to enable/disable command items and set/unset their check/radio marks. This statement is true both for toolbars and menus in Prof-UIS and for those available in MFC/Win32. To remove menu items on-the-fly you should handle the CExtPopupMenuWnd::g_nMsgPrepareMenu registered Windows message as it is done in the DRAWCLI application. It handles this message in the CMainFrame::OnExtMenuPrepare() method and re-sends it to the active view in which the message is finally handled in the CDrawView::OnExtMenuPrepare() method. The latter initializes the OLE verb menu for the currently selected OLE object in the view. You can see how the view’s method performs searching, deleting and inserting of pop-up menu items immediately before menu becomes visible on the screen.

Wang Yang Nov 2, 2004 - 5:32 AM

Thanks a lot  for your instant and constructive replay !!!


I admire your kindness as well as your excellent programming skills!


Thank you again!


 


Best Wishes,


Wang Yang,


Beijing, China,


wy25@mail.bnu.edu.cn