Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 12: Dialog-Based Windows Visual C++ and MFC Fundamentals


// Operations
public:
CFloaterDlg *Floater;


  1. 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;
}


  1. To give the user the ability to display or hide the Floater window, display the
    IDR_MAINFRAME menu and click View

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

  3. Right-click the Floater menu item and click Add Event Handler...

  4. Accept the Message type as COMMAND. Accept the suggested Function Handler
    Name. In the Class List, click CMainFrame then click Add and Edit

  5. 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);
}


  1. Test the application

Free download pdf