Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals
// Operations
public:
CFloaterDlg *Floater;
- Display the MainFrm.cpp file and initialize the Floater variable using the new
operator. Then, use the OnCreate() event to create the floating window:
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
Floater = new CFloaterDlg;
}
...
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
...
Floater->Create(IDD_DLG_FLOATER, this);
return 0;
}
- To give the user the ability to display or hide the Floater window, display the
IDR_MAINFRAME menu and click View - Add a separator under the Status Bar menu item. In the box under the new separator,
add a menu item with a caption of &Floater...and press Enter - Right-click the Floater menu item and click Add Event Handler...
- Accept the Message type as COMMAND. Accept the suggested Function Handler
Name. In the Class List, click CMainFrame then click Add and Edit - Change the MainFrm.cpp file as follows:
void CMainFrame::OnViewFloater()
{
// TODO: Add your command handler code here
// Display the window, even if it is already displaying
Floater->ShowWindow(SW_SHOW);
}
- Test the application