This is a
CCommandBarCtrl extension to fully support the MDI
The implementation consists of three classes:
CCommandBarCtrl2 manages the additional MDI buttons.
CMDIChildWindowImpl2 forwards the size changes to
CMDIChildWinImplTraits2 implements a helper class to
keep the maximize state when creating a new MDI child window.
The class definitions and implementations are in the file
, which is included in the demo project.
You will require the WTL Libraries; these can be downloaded from the
Microsoft site. If the WTL Libraries have no meaning to you, see
Introduction to WTL -
How to use the control in your WTL App
First, include the file
AtlCmdBar2.h in your applications
.cpp file. Then replace the definition of the main frames
CCommandBarCtrl m_CmdBar; with
CCommandBarCtrl2 m_CmdBar; in
Finally replace all instances of
ChildFrm.h. That's all.
03 Oct 2001
- Initial public release.
06 Dec 2001
- Added chevron support (including menu band size update).
- Fixed MDI system menu injection.
- Fixed size problem of MDI system menu.
- Fixed flickering of menu bar during window sizing.
About the implementation
The additional MDI buttons are implemented as custom draw buttons of the
menu toolbar and are drawn via
DrawFrameControl(). These are
added/removed in respond to a size change of the MDI child window.
WM_MDISETMENU has to be handled to insert the MDI
child windows menu into the new frame window menu.
Below are detailed explanations of the most interesting functions.
LRESULT OnMDISetMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
Checks, if the MDI child is maximized and modifies the given frame menu
before it will be passed to the
CCommandBarCtrl handler. Because
the menu toolbar is build in the default handler the MDI buttons are added
after the call.
LRESULT OnMDIChildSized(UINT , WPARAM , LPARAM lParam, BOOL& )
Message send from
CMDIChildWindowImpl2 when the size of the
MDI child window has been changed. Modifies the menu accordingly to the state
of the MDI child. The return value is non-zero if the MDI child is maximized.
LRESULT OnHookMouseMove(UINT , WPARAM , LPARAM , BOOL& bHandled)
Because the file menu button will be drawn as selected when the cursor
will be moved over the MDI child icon this handler resets the current hot
Updates the width of the gap between the last menu item and the MDI
buttons. Called in respond to a size change of the command bar.
bool UpdateMenu(bool fShow, HMENU hMenu)
Inserts or removes the MDI child window menu into the given menu.
void UpdateMDIButtons(bool fShow)
Adds or removes the MDI buttons to the menu toolbar.
void MDIChildChanged(HWND hWndMDIChild)
Modifies the menu and the toolbar according to the state of the given
MDI child window.
HWND Create(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL, DWORD dwStyle = 0, DWORD dwExStyle = 0, UINT nMenuID = 0, LPVOID lpCreateParam = NULL)
HWND CreateEx(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR szWindowName = NULL, DWORD dwStyle = 0, DWORD dwExStyle = 0, LPVOID lpCreateParam = NULL)
Provided to prevent flickering during the creation of maximized MDI child
windows. This is accomplished with setting the redraw flag of the mainframe
LRESULT OnCreate(UINT , WPARAM , LPARAM lParam, BOOL& bHandled)
When the MDI child window is created maximized the MDI client window edge
will be modified to avoid that both windows have the
LRESULT OnGetIcon(UINT , WPARAM wParam, LPARAM , BOOL& )
Loads the icon resource specified in the window class.
LRESULT OnWindowPosChanging(UINT , WPARAM , LPARAM lParam, BOOL& bHandled)
Signals size changes to the
CCommandBarCtrlImpl2 and sets the
maximized flag in
static DWORD GetWndStyle(DWORD dwStyle)
WS_MAXIMIZE style if the maximized flag is set.