How to Create a Status Bar in Every MDI Child Window

Last reviewed: October 10, 1997
Article ID: Q121946
1.00 1.50 1.51 | 1.00 2.00 2.10 4.00
WINDOWS        | WINDOWS NT
kbprg kbcode

The information in this article applies to:

  • The Microsoft Foundation Classes (MFC), included with:

        - Microsoft Visual C++ for Windows, versions 1.0, 1.5, and 1.51
        - Microsoft Visual C++, 32-bit Edition, versions 1.0, 2.0, 2.1, and
          4.0
    

SUMMARY

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

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:

  1. Create an MDI Application by using AppWizard.

  2. Create a new MDI child window class. Derive it from CMDIChildWnd by using Class Wizard.

  3. 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:

    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
       }
    
    

  4. Cut and paste the following definition to the beginning of the newly created child class .CPP file:

    static UINT BASED_CODE indicators[] = {

            ID_SEPARATOR,                 // status line indicator
            ID_INDICATOR_CAPS,
            ID_INDICATOR_NUM,
            ID_INDICATOR_SCRL,
       };
    
    

  5. Add the following public data member in the child class .H file:

    CStatusBar m_wndStatusBar;

  6. Include your new child class .H file into your project .CPP file.

  7. In your project .CPP file, make sure you use your newly derived child window class to replace CMDIChildWnd in AddDocTemplate, as in this example:

    AddDocTemplate(new CMultiDocTemplate(IDR_PROJTYPE,

                         RUNTIME_CLASS(CProjDoc),
                         RUNTIME_CLASS(CNewChild),
                         RUNTIME_CLASS(CProjView)));
    
       Replace PROJ with the project name you provided to AppWizard, and
       replace CNewChild with the new child class derived from CMDIChildWnd.
    
    

  8. Build and run your program. You will see the status bar in every MDI child window.

For Visual C++ 32-bit Edition, version 4.0, the process is simpler:

  1. Create an MDI Application by using AppWizard.

  2. Start ClassWizard. For CChildFrame, create an OnCreate handler for the WM_CREATE message.

  3. 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
          }
    
    

  4. 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,
          };
    
    

  5. Add the following public data member to CChildFrame in CHILDFRM.H:

    CStatusBar m_wndStatusBar;

  6. Build and run your program. You will see the status bar in every MDI child window.


Additional reference words: kbinf status mdi child window 1.00 1.50 2.00
2.10 2.50 2.51 3.00 4.00
KBCategory: kbprg kbcode
KBSubCategory: MfcUI
Keywords : kbcode kbprg
Technology : kbMfc
Version : 1.00 1.50 1.51 | 1.00 2.00 2.10
Platform : NT WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 10, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.