Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 15: Fundamental Controls



  1. Click Finish

  2. In the OnInitDialog() event, set the caption of the button to "Close" 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");

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


  1. Test the application

  2. To close the dialog box, click its System Close button

  3. Display the dialog box. Right-click the button and click Add Event Handler

Free download pdf