Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals



  1. In the Event Handler Wizard, make sure the Message Type is set to BN_CLICKED
    and the Class List is set to CDialog2Dlg. Then click the Add And Edit button

  2. Implement the OnClick event as follows:


void CDialog2Dlg::OnBnClickedBtnClose()
{
// TODO: Add your control notification handler code here
PostQuitMessage(WM_QUIT);
}


  1. To programmatically change the caption of the dialog box, access the OnInitDialog()
    event and set the Caption of the dialog box to "Application Launcher" as follows:


BOOL CDialog2Dlg::OnInitDialog()
{
CDialog::OnInitDialog();

// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon

// TODO: Add extra initialization here
m_BtnClose.SetWindowText("Close");
this->SetWindowText("Application Launcher");

return TRUE; // return TRUE unless you set the focus to a control
}


  1. Add a new button to the upper left section of the dialog box

  2. Set it ID to IDC_BTN_WORDPAD and its Caption to WordPad

  3. Double-click the WordPad button and implement its OnClick event as follows:


void CDialog2Dlg::OnBnClickedBtnWordpad()
{
// TODO: Add your control notification handler code here
WinExec("Write.exe", SW_NORMAL);
}
Free download pdf