Click here to Skip to main content
15,888,521 members
Articles / Desktop Programming / MFC
Article

The Ultimate Toolbox Application Customization

Rate me:
Please Sign up or sign in to vote.
4.63/5 (3 votes)
24 Aug 2007CPOL4 min read 41.6K   582   16   2
Ultimate Toolbox provides a set of classes to allow for application state management and customization.

Visit the Ultimate Toolbox main page for an overview and configuration guide to the Ultimate Toolbox library.

Contents

Overview

Image 1

COXCustomizeManager is a derived class that serves as a control center that provides customization functionality for different aspects of your application. COXCustomizeManager is a container of customize page(s). Each customize page is responsible for customization of a particular area of your application functionality (e.g. customizing menus and toolbars). Refer to the COXCustomizePage class overview and overviews for the standard customize page classes (like COXCustomizeCommandsPage).CDialog

COXCustomizeManager is responsible for initializing all customize pages inserted in the manager. It organizes all pages in groups (by default there is only one group defined - the one that contains standard (predefined) customize pages) and provides navigation facilities by using a shortcut bar control (COXShortcutBar class).

COXCustomizeManager is designed to be easily overridden in order to provide support for custom-defined customize pages. It has many virtual functions that define its behaviour, which can be overridden in order to provide additional customization functionality.

Although the customize manager is easily expandable, in most cases a programmer will use a predefined set of standard customize pages (Customize Commands, Customize Toolbars, Customize Workspace, etc.). COXCustomizeManager provides interface functions for accessing the standard pages and their initialization functions (refer to the class reference for details). In most cases a customization feature will require a programmer to call only one initialization function.

COXCustomizeManager provides a rich set of functions for navigating through customize pages programmatically. These will be useful mostly for programmers who decide to derive their own classes and provide additional functionality.

We've developed many predefined customize pages that will satisfy the more common customization needs (e.g. toolbars, menus, accelerator tables, etc.). All standard pages are documented, and are listed in the overview for the COXCustomizePage class (base class for any customize page).

Note that you do not have to implement your own COXCustomizeManager-derived class in order to specify what standard pages will be included in the customize manager. Moreover, you don't have to include the code that implements the standard pages if you are not interested in using them. For example, in order to include support for customizing toolbars and menus you need to include the following define in your stdafx.h file:

C++
#define OX_CUSTOMIZE_TOOLBARS

The list of all defines that correspond to standard pages can be found in the COXCustomizePage overview in the CHM documentation.

Below you will find the details on how you can use customize manager in your application. (Note that some of the standard pages might require additional initialization steps).

Usage

  1. In your stdafx.h file include defines for the standard pages you are going to use in the customize manager:
C++
#define OX_CUSTOMIZE_TOOLBARS
#define OX_CUSTOMIZE_COMMANDS

These defines will include "Customize Toolbars" and "Customize Commands" standard pages.

  1. Declare a member variable of COXCustomizeManager class in the main window of your application (usually CMainFrame class for SDI/MDI applications)
C++
// customize manager

COXCustomizeManager m_customizeManager;
  1. Handle the WM_CREATE message for the main window and in the handler and call initialization routines for the pages included in the customize manager:
C++
#ifdef OX_CUSTOMIZE_TOOLBARS
VERIFY(m_customizeManager.InitializeToolbars());
#endif //OX_CUSTOMIZE_TOOLBARS

#ifdef OX_CUSTOMIZE_COMMANDS
VERIFY(m_customizeManager.InitializeCommands());
#endif //OX_CUSTOMIZE_COMMANDS

This code will initialize the "Customize Toolbars" and "Customize Commands" standard pages. Note that you have to refer to the documentation for the appropriate way of initializing any particular standard, customized routines because some of them require additional initialization step(s).

Before initializing any page in the Customize manager you have to make sure that the variable that points to application main window is already defined (i.e. AfxGetMainWnd() function returns a pointer to created window). The default MFC implementation sets this variable in the CWinApp-derived class InitInstance() function after loading the frame. Unfortunately, it is too late for some of the standard customize pages. So make sure that you put the following line of code before calling any Initialize... functions:

C++
AfxGetApp()->m_pMainWnd=this;
  1. If you want to save the state of the pages (pages allows you to save the changed settings in the registry) you have to handle WM_CLOSE message for the main window and add the following line of code to this handler:
C++
m_customizeManager.SaveWorkspaceState();
  1. In order to display the customize manager (it is always displayed as modeless window) you can use the following code:
C++
f(!::IsWindow(m_customizeManager.GetSafeHwnd()))
{
    VERIFY(m_customizeManager.Create(COXCustomizeManager::IDD,this));
}
m_customizeManager.SetActiveWindow();
m_customizeManager.ShowWindow(SW_SHOW);

That's all you need to do.

COXCustomizeManager automatically recognizes if it is being used in with the docking windows framework. It behaves differently in a docking windows environment. If your application doesn't use the docking framework then you must to add the following define to your stdafx.h file:

C++
#define OX_CUSTOMIZE_NOTSUPPORTING_DOCKING_FRAMEWORK

For more on the COXCustomizeManager and associated configuration pages, refer to the Application Customization Framework section of the compiled HTML help documentation.

History

Initial CodeProject release August 2007.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
In January 2005, David Cunningham and Chris Maunder created TheUltimateToolbox.com, a new group dedicated to the continued development, support and growth of Dundas Software’s award winning line of MFC, C++ and ActiveX control products.

Ultimate Grid for MFC, Ultimate Toolbox for MFC, and Ultimate TCP/IP have been stalwarts of C++/MFC development for a decade. Thousands of developers have used these products to speed their time to market, improve the quality of their finished products, and enhance the reliability and flexibility of their software.
This is a Organisation

476 members

Comments and Discussions

 
GeneralThe CustimizationDialogBar fails with Office 2003 skin Pin
mapharo30-Sep-10 13:19
mapharo30-Sep-10 13:19 
Generalproblems with COXCustomizeCommandsPage and COXCustomizeShortKeyPage. Pin
mapharo13-Jun-08 14:37
mapharo13-Jun-08 14:37 
I’m having trouble with the COXCustomizeManager, particularly with two pages : the COXCustomizeCommandsPage and the COXCustomizeShortKeyPage. They both present the same page style so I think the problem came from that.
The error that the debug sends is :

OXCustomizeCommandsPage.cpp Line:850

if(hItem==NULL)
{
int nImageIndex=-1;
if(nCommandID!=-1)
{
?VERIFY(m_mapCommands.Lookup(nCommandID,nImageIndex));
if(nImageIndex==-1)
nImageIndex=ID_OX_IMAGEOFFSET_NOIMAGE;
}
else
{
nImageIndex=ID_OX_IMAGEOFFSET_MENUGROUP;
}

hItem=m_treeCommands.InsertItem(sText,nImageIndex,nImageIndex,
hParentItem,TVI_LAST);
ASSERT(hItem!=NULL);
m_treeCommands.SetItemData(hItem,(LPARAM)nCommandID);
}


And in the ShortKey Page the error came from the MFC library Inlines for AFXCMN.H and points to :

_AFXCMN_INLINE int CImageList::GetImageCount() const
{
?ASSERT(m_hImageList != NULL);
return ImageList_GetImageCount(m_hImageList);
}

I have include the OXMain.rc so I don’t know why this errors came up.
Does anyone knows why???
Thanks.

Mauricio Alfaro

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.