計算器單位換算模塊(運行效果圖參見計算器項目綜述)
對於單位換算這一模塊,僅實現了兩個部分,一個是攝氏度與華氏度之間的轉換,另外一個是焦耳與熱卡路里之間的進制轉換。
下面是該模塊開發文檔截圖:
下面是核心代碼:
// MyDlg_3.cpp : implementation file
//
#include "stdafx.h"
#include "簡化調試.h"
#include "簡化調試Dlg.h"
#include "MyDlg_1.h"
#include "MyDlg_2.h"
#include "MyDlg_3.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDlg_3 dialog
CMyDlg_3::CMyDlg_3(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg_3::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg_3)
m_cdegree = 0.0f;
m_fdegree = 0.0f;
m_je = 0.0f;
m_cal = 0.0f;
//}}AFX_DATA_INIT
}
void CMyDlg_3::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg_3)
DDX_Text(pDX, IDC_EDIT1, m_cdegree);
DDX_Text(pDX, IDC_EDIT2, m_fdegree);
DDX_Text(pDX, IDC_EDIT3, m_je);
DDX_Text(pDX, IDC_EDIT4, m_cal);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg_3, CDialog)
//{{AFX_MSG_MAP(CMyDlg_3)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
ON_COMMAND(ID_MENUITEM3, OnMenuitem3)
ON_COMMAND(ID_MENUITEM0, OnMenuitem0)
ON_COMMAND(ID_MENUITEM1, OnMenuitem1)
ON_COMMAND(ID_MENUITEM2, OnMenuitem2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg_3 message handlers
void CMyDlg_3::OnChangeEdit1()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData();
m_fdegree = 32 + m_cdegree * 1.8;
UpdateData(FALSE);
}
void CMyDlg_3::OnChangeEdit2()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData();
m_cdegree = (m_fdegree - 32) / 1.8;
UpdateData(FALSE);
}
void CMyDlg_3::OnChangeEdit3()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData();
m_cal = m_je / 4.184;
UpdateData(FALSE);
}
void CMyDlg_3::OnChangeEdit4()
{
// TODO: If this is a RICHEDIT control, the control will not
// send this notification unless you override the CDialog::OnInitDialog()
// function and call CRichEditCtrl().SetEventMask()
// with the ENM_CHANGE flag ORed into the mask.
// TODO: Add your control notification handler code here
UpdateData();
m_je = m_cal * 4.184;
UpdateData(FALSE);
}
void CMyDlg_3::OnMenuitem3()
{
// TODO: Add your command handler code here
MessageBox("您已處於單位換算模式!");
}
void CMyDlg_3::OnMenuitem0()
{
// TODO: Add your command handler code here
CMyDlg_3::OnCancel();
CMyDlg dlg;
dlg.DoModal();
}
void CMyDlg_3::OnMenuitem1()
{
// TODO: Add your command handler code here
CMyDlg_3::OnCancel();
CMyDlg_1 dlg;
dlg.DoModal();
}
void CMyDlg_3::OnMenuitem2()
{
// TODO: Add your command handler code here
CMyDlg_3::OnCancel();
CMyDlg_2 dlg;
dlg.DoModal();
}