Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Index Visual C++ and MFC Fundamentals



  1. Display the dialog box. Double-click the Calculate button. Accept the suggested
    name of the function and click OK

  2. Implement the event as follows:


// MFCExtTestDlg.cpp : implementation file
//

#include "stdafx.h"
#include "MFCExtTest.h"
#include "MFCExtTestDlg.h"

#include "mfcextent.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMFCExtTestDlg dialog

CMFCExtTestDlg::CMFCExtTestDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMFCExtTestDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMFCExtTestDlg)
m_Number1 = _T("0.00");
m_Number2 = _T("0.00");
m_Result = _T("0.00");
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

...


void CMFCExtTestDlg::OnCalculateBtn()
{
// TODO: Add your control notification handler code here
double Number1, Number2, Result;

UpdateData();

// Evaluate the content of each operand edit box
if( MFCExtensions::IsNumeric(m_Number1) == TRUE )
{
Number1 = MFCExtensions::StringToFloat(m_Number1);
}
else
{
AfxMessageBox("Invalid Number");
Number1 = 0.00;
}

if( MFCExtensions::IsNumeric(m_Number2) == TRUE )
{
Number2 = MFCExtensions::StringToFloat(m_Number2);
}
else
{
Free download pdf