How to Create a Status Bar in Every MDI Child Window

ID: Q121946


The information in this article applies to:
  • The Microsoft Foundation Classes (MFC), included with:
    • Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51
    • Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 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:
    
    \* 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 


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


  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:
    
    \* 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.


  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 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
Version : 1.00 1.50 1.51 | 1.00 2.00 2.10
Platform : NT WINDOWS
Issue type :


Last Reviewed: August 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.