Command Manager

Professional User Interface Suite, Copyright FOSS Software Inc. Help Published with Permission.

When running most Prof-UIS sample applications, you may have noticed that pop-up menus display icons for some commands. The very same icons are set for corresponding commands in toolbars. This feature is automatically provided by the Prof-UIS command manager, which is an object of the CExtCmdManager type and can be accessed from within the entire application with the g_CmdManager smart pointer variable.

The command manager is a named collection of command profiles. Each profile is an object of the CExtCmdProfile class. Each profile has its own unique name and keeps a list of HWND handles. This allows a window to "know" which profile it belongs to.

The most important role of the command profile is to keep descriptions of the commands. The command description is a CExtCmdItem object, which keeps information related to a single command:

  •    identifier
  •    text strings for the menu item, toolbar button, tooltip, and status pane
  •    icon
  •    command usage statistics required for supporting expandable pop-up menus

Most applications are based on a single profile in the command manager. This profile keeps HWND of the main frame window or main dialog, which allows, the main window and all its child controls to find a required command description automatically.

When starting up the application, you should initialize the command manager. Add your command profile to the command manager and then put all the command descriptions into this profile. You may do this at the beginning of the OnCreate() method of the main frame window or in the OnInitDialog() of the main dialog window:

VERIFY(
    g_CmdManager->ProfileSetup(
      "name of the command profile",
      GetSafeHwnd() // HWND of the frame window
      )
    );

If you register your menu bar and/or toolbar resources in the command manager, all their data will be added to the command manager automatically:

VERIFY(
    g_CmdManager->UpdateFromMenu(
      "name of the command profile",
      IDR_MAINFRAME
      )
    );
VERIFY(
    g_CmdManager->UpdateFromMenu(
      "name of the command profile",
      IDR_YourMdiProjectsDOCTYPE
      )
    );
VERIFY(
    g_CmdManager->UpdateFromToolBar(
      "name of the command profile",
      IDR_TOOLBAR1
      )
    );

Finally, notify the command manager about destroying the frame window in CMainFrame::DestroyWindow() (or about the main dialog window in OnOK() and OnCancel()) so that it can release HWND of the window:

g_CmdManager->ProfileWndRemove( GetSafeHwnd() );