Toll Free: (877) 723-1442 U.S. and Canada
Support
ActiveX / COM
Visual C++ / MFC
Customer Spotlight
Corporate Partners
Contact Sales

Call center available M-F 9:00 - 6:00 US Eastern Time.

U.S. and Canada
(877) 723-1442

International
(517) 625-5729

Email

Add intelligent menus

Author: Kirk Stowell
Posted: November 16, 2004
Environment: Visual C++ MFC

The following is a tutorial on how to add intelligent menus to your application. This tutorial assumes that you have already created an application that uses Office style toolbars and menus. For a tutorial on how to create an application that uses Office style toolbars and menus, click here.

Create a simple MDI application using the MFC AppWizard:

  1. Add array of Ids that seem not very important for user.


  2.  static UINT uHideCmds[] =

     {

         ID_FILE_PRINT, ID_FILE_PRINT_PREVIEW, ID_WINDOW_CASCADE

     };



  3. Add to the CMainFrame::OnCreate Intelligent menu initialization:


  4.  // Hide array of commands

     pCommandBars->HideCommands(uHideCmds, _countof(uHideCmds));

     

         // Set "Always Show Full Menus" option to the FALSE

         XTP_COMMANDBARS_OPTIONS* pOptions = pCommandBars->

           GetCommandBarsOptions();

         pOptions->bAlwaysShowFullMenus = FALSE;



  5. Add the OnClose message handler to CMainFrame and add SaveCommandBars(_T("CommandBars")); before the call to the base class. This will save the user’s used commands.


  6.      int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

         {

             ...

     

                 // Load the previous state for toolbars and menus.

                 LoadCommandBars(_T("CommandBars"));

     

             return 0;

         }



  7. Add the OnClose message handler to CMainFrame and add SaveCommandBars(_T("CommandBars")); before the call to the base class. This will save the user’s used commands.


  8.      void CMainFrame::OnClose()

         {

             // Save the current state for toolbars and menus.

             SaveCommandBars(_T("CommandBars"));

             CMDIFrameWnd::OnClose();

         }

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Other products and/or company names may be trademarks or registered trademarks of their respective owners.