Click here to Skip to main content
Click here to Skip to main content

WTL MDI command bar control

By , 5 Dec 2001
 

Sample Image

Introduction

This is a CCommandBarCtrl extension to fully support the MDI architecture.

The implementation consists of three classes:

  • CCommandBarCtrl2 manages the additional MDI buttons.
  • CMDIChildWindowImpl2 forwards the size changes to CCommandBarCtrl2.
  • 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 AtlCmdBar2.h, which is included in the demo project.

Requirements

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 - Part 1.

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 command bar CCommandBarCtrl m_CmdBar; with CCommandBarCtrl2 m_CmdBar; in mainfrm.h. Finally replace all instances of CMDIChildWindowImpl with CMDIChildWindowImpl2 in ChildFrm.h. That's all.

History

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. Additionally, 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.

CCommandBarCtrl2

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 /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)

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 /*uMsg*/, WPARAM /*wParam*/, LPARAM /*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 item.

void UpdateGapWidth()

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.

CMDIChildWindowImpl2

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 window.

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*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 WS_EX_CLIENTEDGE style.

LRESULT OnGetIcon(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)

Loads the icon resource specified in the window class.

LRESULT OnWindowPosChanging(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)

Signals size changes to the CCommandBarCtrlImpl2 and sets the maximized flag in CMDIChildWinImplTraits2.

CMDIChildWinImplTraits2

static DWORD GetWndStyle(DWORD dwStyle)

Adds the WS_MAXIMIZE style if the maximized flag is set.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Bjoern Graf
Web Developer
Germany Germany
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralCompile error due to m_wndMDIClientmemberdima_zh_n31 Mar '03 - 21:21 
Hi,
 
I cannot compile the sample neither my own project due to this line
 
file AtlCmdBar2.h
line 276
 
HWND hWndActiveMDI = (HWND)m_wndMDIClient.SendMessage(WM_MDIGETACTIVE);
 
m_wndMDIClient is not a member of CCommandBarCtrlImpl2 nor its base class CCommandBarCtrlImpl. Did you mean CMDICommandBarCtrlImpl::m_wndMDIClient?
 
Best regards,
Dmitri
GeneralRe: Compile error due to m_wndMDIClientmemberBjoern Graf30 Jul '03 - 19:03 
dima_zh_n wrote:
Did you mean CMDICommandBarCtrlImpl::m_wndMDIClient?
 
Not really. In WTL3.1 (and this is version this code is target to), this is a variable of CCommandBarCtrlImpl. Using CMDICommandBarCtrlImpl will result in two MDI icons and draw the MDI buttons using the WTL7 implementation. Currently, I'm not sure if I'll update the code for WTL7 as it's native MDI command bar control seems to work - the only bad thing I discovered so far is the separation of the MDI system menu and the main menu Smile | :)
GeneralWon't Compile of NT version 4sussAnonymous10 Oct '02 - 3:34 
Tried to compile this on NT version 4 & it wouldn't compile!!!
Tried launching the EXE and found that the Menus all have funny characters, but program appeared OK on Win 2000.
 
What I would like to do is simple replace the MDI Childframe menu with my own which is built from a config file at run time.
 
Any ideas???????

GeneralRe: Won't Compile of NT version 4memberBjoern Graf10 Oct '02 - 6:28 
Anonymous wrote:
Tried to compile this on NT version 4 & it wouldn't compile!!!
 
Hmmm, whithout the compiler error message, I dont have a clue Confused | :confused:
 
Anonymous wrote:
Tried launching the EXE and found that the Menus all have funny characters, but program appeared OK on Win 2000.
 
I'm not sure about this, but it's possible that I use some functions which where introduced with an IE update.
 
Not sure what you mean in the last point.
 
Bjørn.
QuestionDouble-click to close?sussDavid Sullivan16 Aug '02 - 6:06 
How can I make AtlCmdBar2.h work so that double-clicking on the maximized file icon will close the child?

GeneralnitpickingsussAnonymous9 Jul '02 - 8:55 
The mdi icon and buttons are sized incorrectly on windows xp.
 
In GetSystemSettings2(line 487, atlcmdbar2.h), all references to info.iCaptionWidth and info.iCaptionHeight should be changed to info.iSmCaptionWidth and info.iSmCaptionHeight respectively.
 
Like I said, just nitpicking.
Questioncan not receieve WM_KEYDOWNmemberAnonymous17 Apr '02 - 22:41 
Hi,
I created a project with the atlcmdbar2.h. I found that
when i press a key,and the default view window size is maximized,i can not receive WM_KEY_DOWN message in the view window .It seems that the view has not take up the keyboard focus after it was created .

 
hans
GeneralRebar bandmember1111111118 Jan '02 - 0:30 
What about the MDI buttons have the own rebar band? It fixes a behavior when the window is too small to have the MDI buttons. Just look at mmc.exe
 
Vladimir
GeneralAssertion failedmemberrdo27 Nov '01 - 3:04 
this is very strange, but when i run my program in debug build i get assertion failure( ATLASSERT(mii.hSubMenu != NULL) in CCommandBarCtrlImpl::AttachMenu())
but in release build everything works just fine??!!
GeneralRe: Assertion failedmemberBjoern Graf2 Dec '01 - 13:53 
Just fixed this. It happened because WM_MDIGETACTIVE returned a NULL window handle and therefore no valid menu handle could be obtained.
 
Bjørn.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 6 Dec 2001
Article Copyright 2001 by Bjoern Graf
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid