Chapter 15: Fundamental Controls Visual C++ and MFC Fundamentals
CubeSide = atof(StrCubeSide);
CubeArea = CubeSide * 6;
CubeVolume = CubeSide * CubeSide * CubeSide;
sprintf(StrCubeArea, "%.3f", CubeArea);
sprintf(StrCubeVolume, "%.3f", CubeVolume);
edtCubeArea->SetWindowText(StrCubeArea);
edtCubeVolume->SetWindowText(StrCubeVolume);
}
void CGeome3D::OnBnClickedBtnBcalc()
{
// TODO: Add your control notification handler code here
// Related Calculations of the box
double BoxLength, BoxWidth, BoxHeight, BoxArea, BoxVolume;
CEdit *edtBoxLength, *edtBoxWidth, *edtBoxHeight,
*edtBoxArea, *edtBoxVolume;
char StrLength[10], StrWidth[10], StrHeight[10],
StrArea[10], StrVolume[10];
edtBoxLength = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BLENGTH));
edtBoxWidth = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BHEIGHT));
edtBoxHeight = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BWIDTH));
edtBoxArea = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BAREA));
edtBoxVolume = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_BVOL));
edtBoxLength->GetWindowText(StrLength, 10);
edtBoxWidth->GetWindowText(StrWidth, 10);
edtBoxHeight->GetWindowText(StrHeight, 10);
BoxLength = atof(StrLength);
BoxWidth = atof(StrWidth);
BoxHeight = atof(StrHeight);
BoxArea = 2 * ((BoxLength + BoxWidth) +
(BoxLength + BoxHeight) +
(BoxWidth + BoxHeight));
BoxVolume = BoxLength * BoxWidth * BoxHeight;
sprintf(StrArea, "%.3f", BoxArea);
sprintf(StrVolume, "%.3f", BoxVolume);
edtBoxArea->SetWindowText(StrArea);
edtBoxVolume->SetWindowText(StrVolume);
}
- Execute the application. Test the controls in the Quadrilateral property page by
providing numeric values in the Side, the Length, and the Height edit boxes before
clicking their corresponding button