Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

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


// TODO: Add your control notification handler code here
double SquareSide, SquarePerimeter, SquareArea;
char StrSquareSide[10], StrSquarePerimeter[10], StrSquareArea[10];

m_SquareSide.GetWindowText(StrSquareSide, 10);
SquareSide = atof(StrSquareSide);
SquarePerimeter = SquareSide * 4;
SquareArea = SquareSide * SquareSide;

sprintf(StrSquarePerimeter, "%.3f", SquarePerimeter);
sprintf(StrSquareArea, "%.3f", SquareArea);

m_SquarePerimeter.SetWindowText(StrSquarePerimeter);
m_SquareArea.SetWindowText(StrSquareArea);
}

void CQuadrilateral::OnBnClickedBtnRcalc()
{
// TODO: Add your control notification handler code here

double RectLength, RectHeight, RectPerimeter, RectArea;
char StrRectLength[10], StrRectHeight[10],
StrRectPerimeter[10], StrRectArea[10];

m_RectLength.GetWindowText(StrRectLength, 10);
RectLength = atof(StrRectLength);
m_RectHeight.GetWindowText(StrRectHeight, 10);
RectHeight = atof(StrRectHeight);

RectPerimeter = 2 * (RectLength + RectHeight);
RectArea = RectLength * RectHeight;

sprintf(StrRectPerimeter, "%.3f", RectPerimeter);
sprintf(StrRectArea, "%.3f", RectArea);

m_RectPerimeter.SetWindowText(StrRectPerimeter);
m_RectArea.SetWindowText(StrRectArea);
}


  1. Completer the controls events of the Geome3D.cpp source as follows:


// Geome3D.cpp : implementation file
//

...


// CGeome3D message handlers
void CGeome3D::OnBnClickedBtnUcalc()
{
// TODO: Add your control notification handler code here
// Related Calculations of the cube
double CubeSide, CubeArea, CubeVolume;
CEdit *edtCubeSide, *edtCubeArea, *edtCubeVolume;
char StrCubeSide[10], StrCubeArea[10], StrCubeVolume[10];

edtCubeSide = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_USIDE));
edtCubeArea = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_UAREA));
edtCubeVolume = reinterpret_cast<CEdit *>(GetDlgItem(IDC_EDT_UVOL));

edtCubeSide->GetWindowText(StrCubeSide, 10);
Free download pdf