Index Visual C++ and MFC Fundamentals
Button IDC_CALCULATE C&alculate
Static Text GCD:
Edit Control IDC_GCD
Button IDCANCEL &Close
- Add a Value variable for the IDC_NUMBER1 control and name it m_Number1
- Add a Value variable for the IDC_NUMBER2 control and name it m_Number2
- Add a Value variable for the IDC_GCD control and name it m_GCD
- To add the library to the current project, on the main menu, click Project -> Add
Existing Item... and select BusMath.lib - 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);
}
- Test the application. Here is an example: