Chapter 16: Text-Based Controls Visual C++ and MFC Fundamentals
- 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 - Implement the OnClick event as follows:
void CDialog2Dlg::OnBnClickedBtnClose()
{
// TODO: Add your control notification handler code here
PostQuitMessage(WM_QUIT);
}
- 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
}
- Add a new button to the upper left section of the dialog box
- Set it ID to IDC_BTN_WORDPAD and its Caption to WordPad
- 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);
}