Command Bar MDI Menu Control

Command Bar MDI Menu Control

This article was submitted .

This little control class fixes one of the most reported WTL bugs up until WTL version 7.0 !

It adds the maxmimize/restore/close Menu Control to the Command Bar when a MDI client window is maximized.

The most recent version of WTL (version 7.0) includes a fix for this problem, so there is no longer any need to get this one.

About the implementation

The control itself is a toolbar implementation. It adds itself as message listener on several of the parent windows. The toolbar then spawns 3 ownerdrawn buttons - one for each of the system buttons.
The control is added as a ReBar band to the CMainFrame ReBar. The band is hidden when no MDI client is maximized.

I'm still puzzled why the ReBar band gets added at the correct position (in the top/right corner). You see, there is nothing in the ReBar API that allows you to set the positions.
But it seems to work.

How to use it

Add a member variable to your main window frame...
CMdiRebarFix m_fix;
In the OnCreate() event handler, initialise the control after the MDI Client has been created and the ReBar bands populated:
  LRESULT OnCreate(UINT /*uMsg*/, 
                   WPARAM /*wParam*/, 
                   LPARAM /*lParam*/, 
                   BOOL& /*bHandled*/)
    AddSimpleReBarBand(hWndToolBar, NULL, TRUE);


    // Create menu-control
    m_fix.Create(m_hWnd, rcDefault, NULL, 
    m_fix.AddSystemReBarBand(m_hWndMDIClient, m_hWndToolBar);

Source Code Dependencies

Microsoft WTL 3.1 Library

Download Files

DownloadSource Code (4 Kb)

To the top