Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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



  1. Close the application and return to MSVC

  2. In order to enable the Apply button, we need to have it.
    To redisplay the Apply button, change the CGeomeSheet::OnInitDialog() event as
    follows:


BOOL CGeomeSheet::OnInitDialog()
{
BOOL bResult = CPropertySheet::OnInitDialog();

// TODO: Add your specialized code here
// A pointer to each button we will need
CButton *btnOK, *btnCancel, *btnApply, *btnHelp;
// We will need to location and dimensions of Apply and Help
CRect RectCancel, RectApply, RectHelp;

// Get handles to all buttons
btnOK = reinterpret_cast<CButton *>(GetDlgItem(IDOK));
btnCancel = reinterpret_cast<CButton *>(GetDlgItem(IDCANCEL));
btnApply = reinterpret_cast<CButton *>(GetDlgItem(ID_APPLY_NOW));
btnHelp = reinterpret_cast<CButton *>(GetDlgItem(IDHELP));

// Get the location and the dimensions of the buttons
btnCancel->GetWindowRect(&RectCancel);
btnApply->GetWindowRect(&RectApply);
btnHelp->GetWindowRect(&RectHelp);

// Destroy the Help button
btnHelp->DestroyWindow();

// Convert the location and dimensions to screen coordinates
ScreenToClient(&RectCancel);
ScreenToClient(&RectApply);
ScreenToClient(&RectHelp);

// Put the Apply button where the Help button was
btnApply->SetWindowPos(NULL, RectHelp.left, RectHelp.top, 0, 0,
SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW);
// Put the Cancel button where the Apply button was
Free download pdf