Microsoft KB Archive/121946

= How to Create a Status Bar in Every MDI Child Window =

Article ID: 121946

Article Last Modified on 11/21/2006

-

APPLIES TO

 Microsoft Foundation Class Library 4.2, when used with:  Microsoft Visual C++ 1.0 Professional Edition

 Microsoft Visual C++ 1.5 Professional Edition

 Microsoft Visual C++ 1.51

 Microsoft Visual C++ 1.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.0 Professional Edition</li></ul>

 Microsoft Visual C++ 2.1</li></ul>

 Microsoft Visual C++ 4.0 Standard Edition</li></ul> </li></ul>

-

<div class="notice_section">

This article was previously published under Q121946

<div class="summary_section">

SUMMARY
By using the technique described in this article, you can have a status bar in every child window of an MDI Application.

<div class="moreinformation_section">

MORE INFORMATION
For Visual C++ for Windows and Visual C++ 32-bit Edition version through 2.x, use the following steps to create a status bar in every child window of an MDI Application:

<ol> Create an MDI Application by using AppWizard.</li> Create a new MDI child window class. Derive it from CMDIChildWnd by using Class Wizard.</li>  For the new class, create an OnCreate handler for the WM_CREATE message by using Class Wizard. You can cut and paste the following code from the MAINFRAME.CPP file to the OnCreate handler: \* kbon if (!m_wndStatusBar.Create(this) ||         !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) {     TRACE("Failed to create status bar\n"); return -1;      // fail to create } \* kboff </li>  Cut and paste the following definition to the beginning of the newly created child class .CPP file: \* kbon static UINT BASED_CODE indicators[] = {       ID_SEPARATOR,                 // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; \* kboff </li>  Add the following public data member in the child class .H file: CStatusBar m_wndStatusBar; </li> Include your new child class .H file into your project .CPP file.</li>  In your project .CPP file, make sure you use your newly derived child window class to replace CMDIChildWnd in AddDocTemplate, as in this example: \* kbon AddDocTemplate(new CMultiDocTemplate(IDR_PROJTYPE, RUNTIME_CLASS(CProjDoc), RUNTIME_CLASS(CNewChild), RUNTIME_CLASS(CProjView))); \* kboff Replace PROJ with the project name you provided to AppWizard, and replace CNewChild with the new child class derived from CMDIChildWnd. </li> Build and run your program. You will see the status bar in every MDI child window.</li></ol>

For Visual C++ 32-bit Edition, version 4.0, the process is simpler: <ol> Create an MDI Application by using AppWizard.</li> Start ClassWizard. For CChildFrame, create an OnCreate handler for the WM_CREATE message.</li> <li> Edit CChildFrame::OnCreate in CHILDFRM.CPP. Copy and paste the following code from the CMainFrame::OnCreate (in MAINFRM.CPP): if (!m_wndStatusBar.Create(this) ||         !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) {           TRACE0("Failed to create status bar\n"); return -1;     // fail to create }                           </li> <li> Copy and paste the following declaration/definition from the top of MAINFRM.CPP to the top of CHILDFRM.CPP, immediately after the END_MESSGE_MAP macro: static UINT indicators[] = {           ID_SEPARATOR,           // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, };                           </li> <li> Add the following public data member to CChildFrame in CHILDFRM.H:    CStatusBar m_wndStatusBar; </li> <li>Build and run your program. You will see the status bar in every MDI child window.</li></ol>

Additional query words: kbinf status mdi child window 1.00 1.50 2.00 2.10 2.50 2.51 3.00 4.00

Keywords: kbcode KB121946

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.