Command Bar MDI Menu Control (original) (raw)
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*/)
{
...
CreateSimpleReBar(ATL_SIMPLE_REBAR_NOBORDER_STYLE);
AddSimpleReBarBand(hWndCmdBar);
AddSimpleReBarBand(hWndToolBar, NULL, TRUE);
CreateSimpleStatusBar();
CreateMDIClient();
m_CmdBar.SetMDIClient(m_hWndMDIClient);
// Create menu-control
m_fix.Create(m_hWnd, rcDefault, NULL,
ATL_MDI_SYSTEM_CMDBAR_PANE_STYLE);
m_fix.AddSystemReBarBand(m_hWndMDIClient, m_hWndToolBar);
...
}