Guides & Tutorials (beta)

Upgrading Toolkit Standard to Toolkit Pro - Add customization to toolbars and menus

by Kirk Stowell Visual C++ Created on 11/16/2007  |  Updated on 07/31/2024 0/5 ( 0 votes )
  1. Add a ON_COMMAND for XTP_ID_CUSTOMIZE to the message map for CMainFrame. This will handle setup and display for the toolbar and menu customization dialog.

    MainFrm.cpp:
    BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    //}}AFX_MSG_MAP
    ON_COMMAND(XTP_ID_CUSTOMIZE, OnCustomize)
    END_MESSAGE_MAP()
    
    MainFrm.h:
    //{{AFX_MSG(CMainFrame)
    afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
    //}}AFX_MSG
    afx_msg void OnCustomize();
    DECLARE_MESSAGE_MAP()
    
  2. Add the body for the OnCustomize function:
    void CMainFrame::OnCustomize()
    {
        // Get a pointer to the Command Bar object.
        CXTPCommandBars* pCommandBars = GetCommandBars();
        if(pCommandBars != NULL)
        {
            //
    Instantiate the customize dialog object.
            CXTPCustomizeSheet dlg(pCommandBars);
    
            // Add the options page to the customize dialog.
            CXTPCustomizeOptionsPage pageOptions(&dlg);
            dlg.AddPage(&pageOptions);
    
            // Add the commands page to the customize dialog.
            CXTPCustomizeCommandsPage* pCommands =
                dlg.GetCommandsPage();
            pCommands->AddCategories(IDR_MDISAMTYPE);
    
            // Use the command bar manager to initialize the 
            // customize dialog.
            pCommands->InsertAllCommandsCategory();
            pCommands->InsertBuiltInMenus(IDR_MDISAMTYPE);
            pCommands->InsertNewMenuCategory();
    
            //
    Display the dialog.
            dlg.DoModal();
        }
    }
    
  3. Add LoadCommandBars(_T("CommandBars")); to the OnCreate function for CMainFrame. This will restore the previous state of your toolbar and menus plus any customization made.
    int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
        ...
    
            // Load the previous state for toolbars and menus.
            LoadCommandBars(_T("CommandBars"));
    
        return 0;
    }
    
  4. Add the OnClose message handler to CMainFrame and add SaveCommandBars(_T("CommandBars")); before the call to the base class. This will save the current state of your toolbar and menus in plus any customization made.
    void CMainFrame::OnClose()
    {
        // Save the current state for toolbars and menus.
        SaveCommandBars(_T("CommandBars"));
        CMDIFrameWnd::OnClose();
    }
    

    Tutorial

    Tutorial

User Comments

No comments yet, sign in to comment.

Secure Transactions

Online transactions are secure and protected.


Ssl seal 1
This site is protected by Trustwave's Trusted Commerce program
CompliAssure Secured

Money Back Guarantee

If you are not 100% happy with your purchase within 30 days, you can return it for any reason. Your satisfaction is our priority!


Satisfication Guarantee

Contact sales@codejock.com for more details.