6.4. Control bars, status bars, toolbars, dialog bars.

6.4.1. How do I add a combobox to my toolbar?

You can do this using the CToolBar::SetButtonInfo() method. The MFC sample ctrlbars shows how to do this in file mainfrm.cpp. Basically you call SetButtonInfo to create a blank space (TBBS_SEPARATOR)for the combo box, with the resource ID of the help and tool tip for the combobox. You then use GetItemRect to get the bounding rectangle of the combobox, and create a combobox window of your own in that space.

scot@stingray.com, 6/1/95 martynl@cix.compulink.co.uk - updated.

6.4.2. How do I update the text of a pane in a status bar?

By default, a CStatusBar pane is not enabled when the pane is created. To activate a pane, you must call the ON_UPDATE_COMMAND_UI() macro for each pane on the status bar and update the panes. Because panes do not send WM_COMMAND messages, you cannot use ClassWizard to activate panes; you must type the code manually. For example, suppose one pane has ID_INDICATOR_PAGE as its identifier and that it contains the current page number in a document. To make the ID_INDICATOR_PAGE pane display text, add the following to a header file (probably the MAINFRM.H file):

afx_msg void OnUpdatePage(CCmdUI *pCmdUI);

Add the following to the application message map:

ON_UPDATE_COMMAND_UI(ID_INDICATOR_PAGE, OnUpdatePage)

Add the following to a source code file (probably MAINFRM.CPP):

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
    pCmdUI->Enable();
}

To display text in the panes, either call SetPaneText() or call CCmdUI::SetText() in the OnUpdate() function. For example, you might want to set up an integer variable m_nPage that contains the current page number. Then, the OnUpdatePage() function might read as follows:

void CMainFrame::OnUpdatePage(CCmdUI *pCmdUI)
{
    pCmdUI->Enable();
    char szPage[16];
    wsprintf((LPSTR)szPage, "Page %d", m_nPage);
    pCmdUI->SetText((LPSTR)szPage);
}

This technique causes the page number to appear in the pane during idle processing in he same manner that the application updates other indicators.

MSVC Knowledge Base 6/4/94

6.4.3. How do I make my CToolBar customizable at run-time?

You might consider reading article "CToolBarCtrl :Handling Customization Notifications" in the Product Documentation of VC++ 2.1.

Here is the relevant extract :

"A Windows toolbar common control has built-in customization features, including a system-defined customization dialog box, which allow the user to insert, delete, or rearrange toolbar buttons. The application determines whether the customization features are available and controls the extent to which the user can customize the toolbar. These customization features are available in the CToolBarCtrl class but not in the current CToolBar class.

You can make these customization features available to the user by giving the toolbar the CCS_ADJUSTABLE style. The customization features allow the user to drag a button to a new position or to remove a button by dragging it off the toolbar. In addition, the user can double-click the toolbar to display the Customize Toolbar dialog box, which allows the user to add, delete, and rearrange toolbar buttons. The application can display the dialog box by using the Customize member function."

R.Rajendran (NetQuest), 76041.2245@compuserve.com,

MSMFC Forum, May-9-95

If you want to make a standard MFC CToolBar customizable, you can download CUSBAR.ZIP from the MSMFC library on CompuServe. This package implements CCustomTolbar, the run-time customizable toolbar and also provides the necessary user tools (customization dialog box including the code for a bitmapped listbox). Freeware.

Patrick Philippot, 8/3/95 via email on CSERVE

6.4.4. How do I turn off the toolbar or status bar?

You can turn the status bar off in any of your views (i.e. in the OnViewStatusBar() method you describe above) with the following code:

if( ((CMainFrame*)GetParent())->m_wndToolBar.IsWindowVisible() )
{
    GetParent()->SendMessage(WM_COMMAND, ID_VIEW_TOOLBAR, 0L);
}
if( ((CMainFrame*)GetParent())->m_wndStatusBar.IsWindowVisible() )
{
    GetParent()->SendMessage(WM_COMMAND, ID_VIEW_STATUS_BAR, 0L);
}

Use 1L instead of 0L for the SendMessage's lParam to turn the bars on.

JKBenjamin@aol.com via mfc-l, 5/16/95

6.4.5. How do I create a toolbar/statusbar in a dialog?

See section 6.3.5. of this FAQ

6.4.6. Why doesn't MFC support the new controls provided by IE?

6.4.7. Why doesn't MFC have toolbars like the Office 97 applications?

6.4.8. Why doesn't MFC support command bar menus like the Visual C++ IDE?

A: The new user interface style provided by IE is implemented by a version of COMCTL32.DLL that's still in beta. The beta import library, DLL, and documentation is available in the ActiveX 3.01 SDK and is available for download from Microsoft's web site. Since the controls are still in beta, MFC doesn't support them. When they're available in their final version, you can assume that a version of MFC that supports them will be forthcoming.

The IDE and the Office applications do not use the COMCTL32.DLL implementations of those controls, and therefore aren't concerned

with the release state of the system implementation library.

-.B ekiM - mikeblas@microsoft.com.

Note: the IE control is called Rebar and there was a very good MSJ article about it. It is useful ONLY if you want to implement IE3/4 style toolbars. The toolbars in VC++ 5.x and Office 97 are different - they are called Command bars. THEY ARE NOT REBARS - the differences?

If you want to play with rebar you need the files COMMCTRL.H and COMCTL32.LIB that comes with the ActiveX SDK available at http://www.microsoft.com/intedev/sdk/.

Also, for more information take a look at the REBAR-Sample available at

http://www.microsoft.com/win32dev/ui/rebar.htm

FYI, Stingray Software has implemented Office97/DevStudio style command bars in Objective Toolkit - check out the demo at http://www.stingray.com.