Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Index Visual C++ and MFC Fundamentals


Button IDC_CALCULATE C&alculate
Static Text GCD:
Edit Control IDC_GCD
Button IDCANCEL &Close


  1. Add a Value variable for the IDC_NUMBER1 control and name it m_Number1

  2. Add a Value variable for the IDC_NUMBER2 control and name it m_Number2

  3. Add a Value variable for the IDC_GCD control and name it m_GCD

  4. To add the library to the current project, on the main menu, click Project -> Add
    Existing Item... and select BusMath.lib

  5. On the dialog box, double-click the Calculate button and implement it OnClick event
    as follows:


// BusMathTest2Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "BusMathTest2.h"
#include "BusMathTest2Dlg.h"
#include ".\busmathtest2dlg.h"
#include "bmcalc.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

// CBusMathTest2Dlg dialog

CBusMathTest2Dlg::CBusMathTest2Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CBusMathTest2Dlg::IDD, pParent)
, m_Number1(_T("0"))
, m_Number2(_T("0"))
, m_GCD(_T("0"))
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

...


void CBusMathTest2Dlg::OnBnClickedCalculate()
{
// TODO: Add your control notification handler code here
int Nbr1, Nbr2, Result;

UpdateData(TRUE);

Nbr1 = atoi(m_Number1);
Nbr2 = atoi(m_Number2);
Result = GreatestCommonDivisor(Nbr1, Nbr2);

m_GCD.Format("%d", Result);

UpdateData(FALSE);
}


  1. Test the application. Here is an example:

Free download pdf