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:
- Create an MDI Application by using AppWizard.
- Create a new MDI child window class. Derive it from CMDIChildWnd by
using Class Wizard.
- 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
}
- 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,
};
- Add the following public data member in the child class .H file:
CStatusBar m_wndStatusBar;
- Include your new child class .H file into your project .CPP file.
- 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.
- 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:
- Create an MDI Application by using AppWizard.
- Start ClassWizard. For CChildFrame, create an OnCreate handler for the
WM_CREATE message.
- 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
}
- 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,
};
- Add the following public data member to CChildFrame in CHILDFRM.H:
CStatusBar m_wndStatusBar;
- Build and run your program. You will see the status bar in every
MDI child window.
|