MDI list in the status bar ( and a custom Window List dialog )

Tuesday Oct 1st 2002 by Iuri Apollonio

MDI list in the status bar ( and a custom Window List dialog )

Download demo 141K

tabstatus.gif (6K)

1. What is this ?

Some time ago, Carlos Alberto Silva asked me for a way to display in the Window dialog list different names from the ones in title bar. We end up with this thing: it's basically a replacement for the standard Window List Dialog (the one from the Window menu, I mean) and a tab control inserted in the status bar acting like the start menu bar.
The title of the MDI windows can be different from the one displayed in the title bar.

2. How to implement this thing

You'll need to add to your project those classes:
  • CViewManager

  • CWindowListDlg

  • CWindowTabCtrl

The CWindowListDlg is a dialog resource, so add it using the standard add components way or manually copy its dialog template resource.
Now inlude in the view cpp file and in the mainframe cpp this header:

#include "ViewManager.h"

In the mainframe, get an handler for the wm_close message and write this:

void CMainFrame::OnClose() 
	theViewManager.bClosing = true;


In the view contructor, add this line:

	theViewManager.AddView("", this);

and it the view destructor, this one:


Last, in the view OnInitialUpdate we can define the view name:

void CMDIWindListView::OnInitialUpdate() 
	CMDIWindListDoc * pDoc = GetDocument();
	CString cs = pDoc->GetTitle();
	cs += " -with custom text for window list";

	theViewManager.SetViewName(cs, this);

With the SetViewName function we give the name we want to be displayed in the status bar and in the window dialog list. If the standard name is good, simply pass the document.GetTitle() text. You'll need to call this function every time the title of your view changes (usually after a save).

3. Adding the status bar

If we want the status bar like the desktop bar, we'll need to do this modify to the mainframe.
First add in the CMainFrame::OnCreate this line:
theWindowTab.Create(WS_CHILD|WS_VISIBLE|TCS_BUTTONS|TCS_FIXEDWIDTH|TCS_SINGLELINE|TCS_FORCELABELLEFT, CRect(0,0,0,0), &m_wndStatusBar, 1000); Change the 1000 used as hardcode value for the tab control as you like; it's not good practice to hard code the controls value.
Then, get an handler for the wm_size message and write this:

void CMainFrame::OnSize(UINT nType, int cx, int cy) 
	CMDIFrameWnd::OnSize(nType, cx, cy);

	if (m_wndStatusBar.GetSafeHwnd() && theWindowTab.GetSafeHwnd())
		CRect rc;
		m_wndStatusBar.GetItemRect(0, rc);
		theWindowTab.SetWindowPos(0,rc.left,,rc.Width(), rc.Height(), SWP_NOZORDER);

In this sample, I putted the tab control containing the windows in the status bar first pane; if you want it to be as large as the status bar, try this:

	if (m_wndStatusBar.GetSafeHwnd() && theWindowTab.GetSafeHwnd())
		CRect rc;

		theWindowTab.SetWindowPos(0,0,0,rc.Width(), rc.Height(), SWP_NOZORDER);

Or, if you want to put the tab in another pane, simply change the index of the statusbar.GetItemRect.

4. The custom Window List Dialog

The custom window list dialog is invoked with the function:


Simply make a menu item named "my window list", handle it in mainframe and call the function above.

That's all. The code is mine, the concept is of Carlos. Enjoy!

Last updated: 2 July 1998

Mobile Site | Full Site
Copyright 2017 © QuinStreet Inc. All Rights Reserved