How-to: Handling CMFCOutlookBar Tab Change Notifications


Action


The CMFCOutlookBar class has an underlying CMFCOutlookBarTabCtrl to which you can add tabs. These appear as tab page buttons in the CMFCOutlookBar.

If you call CMFCOutlookBar::SetMode2003 to set the Office 2003 UI mode then the CMFCOutlookBar will contain a toolbar window as well. In 2003 mode, if you collapse the tab page buttons by sliding the divider between the tab page buttons and the tab view pane then as each tab page button is removed, a corresponding toolbar button is added to the toolbar. Furthermore, if you size the entire CMFOutlookBar so that the window is not wide enough to display all of the toolbar buttons, then the toolbar chevron button context menu will contain a menu item for each tab page button that is not visible and does not have a toolbar button.

When you click the tab page button, or it's corresponding toolbar button, or it's corresponding chevron button menu item, the corresponding tab becomes the active tab displayed in the CMFCOutookBar. If you wish to do custom processing when the tab is changed you can handle the registered message AFX_WM_CHANGE_ACTIVE_TAB that is sent to your application main frame window.

More Information


AFX_WM_CHANGE_ACTIVE_TAB is a custom windows message registered by MFC in afxbasetabctrl.cpp. This message is sent to the main frame window when either:

  1. The active tab is changed by clicking on a tab page button. This message is not sent if the corresponding tab is currently active
  2. A CMFCOutlookBar toolbar button is clicked (2003 mode). This message is sent even if the corresponding tab is currently active
  3. A chevron button menu item is clicked (2003 mode). This message is sent even if the corresponding tab is currently active
The WPARAM message parameter will contain the zero based tab index of the clicked tab.
The LPARAM message parameter will contain the 'this' pointer of the CMFCOutlookBarTabCtrl object if you clicked a tab page button, or NULL for a toolbar button or chevron menu.

To handle the active tab change message you can add a message handler for this message in your mainframe window:

Here is the message map entry you need.

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWndEx)
...
ON_REGISTERED_MESSAGE(AFX_WM_CHANGE_ACTIVE_TAB,OnChangeActiveTab)
...
END_MESSAGE_MAP()

A possible OnChangeActiveTab handler:

LRESULT CMainFrame::OnChangeActiveTab(WPARAM wparam,LPARAM lparam)
{
CString message;
message.Format(_T(
"Tab %d clicked"),(int)wparam+1);
AfxMessageBox(message);
 
return 1;
}