📄 testdlg.cpp
字号:
/************************************************************
Copyright (C), 1988-1999, Huawei Tech. Co., Ltd.
FileName: test.cpp
Author: 陈高维 Version : 1.0 Date:2007.811
Description: // 模块描述
Version: // 版本信息
Function List: Onadd()...............加法
Onjian()..............减法
Onchen()..............乘法
Onchu().............. 除法
Onzhuanhuan().........翻译转换
OnOK()................清空
1. -------
History: // 历史修改记录
<author> <time> <version > <desc>
David 96/10/12 1.0 build this moudle
***********************************************************/
// testdlg.cpp : implementation file
//
#include "stdafx.h"
#include "简单计算.h"
#include "ctestdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// ctestdlg dialog
ctestdlg::ctestdlg(CWnd* pParent /*=NULL*/)
: CDialog(ctestdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(ctestdlg)
m_num2 = 0.0;
m_num1 = 0.0;
m_num3 = 0.0;
//}}AFX_DATA_INIT
}
void ctestdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(ctestdlg)
DDX_Text(pDX, IDC_EDIT2, m_num2);
DDX_Text(pDX, IDC_EDIT1, m_num1);
DDX_Text(pDX, IDC_EDIT3, m_num3);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(ctestdlg, CDialog)
//{{AFX_MSG_MAP(ctestdlg)
ON_BN_CLICKED(IDC_add, Onadd)
ON_BN_CLICKED(IDC_jian, Onjian)
ON_BN_CLICKED(IDC_chen, Onchen)
ON_BN_CLICKED(IDC_chu, Onchu)
ON_BN_CLICKED(IDC_zhuanhuan, Onzhuanhuan)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// ctestdlg message handlers
void ctestdlg::Onadd()
{
// TODO: Add your control notification handler code here
/* double num1,num2,num3;
char ch1[40],ch2[40],ch3[40];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,40);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,40);
num1=atof(ch1);
num2=atof(ch2);
num3=num1+num2;
// ftoa(num3,ch3,10); // 10 表示10进制
ch3=(char)num3;
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
*/
/*
int num1,num2,num3;
char ch1[40],ch2[40],ch3[40];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,40);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,40);
num1=atoi(ch1);
num2=atoi(ch2);
num3=num1+num2;
itoa(num3,ch3,10); // 10 表示10进制
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
*/
double num1,num2,num3;
CString str;
char ch1[40],ch2[40],ch3[40];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,40);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,40);
num1=atof(ch1);
num2=atof(ch2);
num3=num1+num2;
// ftoa(num3,ch3,10); // 10 表示10进制
// ch3=(char)num3;
_gcvt( num3, 7, ch3 );
//把浮点型数据转化成字符串
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
void ctestdlg::Onjian()
{
// TODO: Add your control notification handler code here
double num1,num2,num3;
CString str;
char ch1[40],ch2[40],ch3[40];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,40);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,40);
num1=atof(ch1);
num2=atof(ch2);
num3=num1-num2;
// ftoa(num3,ch3,10); // 10 表示10进制
// ch3=(char)num3;
_gcvt( num3, 7, ch3 );
//把浮点型数据转化成字符串
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
void ctestdlg::Onchen()
{
// TODO: Add your control notification handler code here
double num1,num2,num3;
CString str;
char ch1[40],ch2[40],ch3[40];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,40);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,40);
num1=atof(ch1);
num2=atof(ch2);
num3=num1*num2;
// ftoa(num3,ch3,10); // 10 表示10进制
// ch3=(char)num3;
_gcvt( num3, 7, ch3 ); //把浮点型数据转化成字符串
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
void ctestdlg::Onchu()
{
// TODO: Add your control notification handler code here
double num1,num2,num3;
char ch1[16],ch2[16],ch3[16];
GetDlgItem(IDC_EDIT1)->GetWindowText(ch1,16);
GetDlgItem(IDC_EDIT2)->GetWindowText(ch2,16);
num1=atof(ch1);
num2=atof(ch2);
if (num2==0)
{
MessageBox("被除数不能为0!");
num3=0;
//ch3="被除数不能为0!";
//showmessage("cuowu");
}
else
{
num3=num1/num2;
}
_gcvt( num3, 7, ch3 );
GetDlgItem(IDC_EDIT3)->SetWindowText(ch3);
}
void ctestdlg::Onzhuanhuan()
{
// TODO: Add your control notification handler code here
CString str;
if (GetDlgItem(IDC_STATIC1)->GetWindowText(str),str=="Number1 :")
//判断现在是英文界面还是中文界面
{
GetDlgItem(IDC_STATIC1)->SetWindowText("数值一 :");
GetDlgItem(IDC_STATIC2)->SetWindowText("数值二 :");
GetDlgItem(IDC_STATIC3)->SetWindowText("结果值 :");
GetDlgItem(IDOK)->SetWindowText("清空");
GetDlgItem(IDCANCEL)->SetWindowText("退出");
GetDlgItem(IDC_add)->SetWindowText("加");
GetDlgItem(IDC_jian)->SetWindowText("减");
GetDlgItem(IDC_chen)->SetWindowText("乘");
GetDlgItem(IDC_chu)->SetWindowText("除");
}
else
{
GetDlgItem(IDC_STATIC1)->SetWindowText("Number1 :");
GetDlgItem(IDC_STATIC2)->SetWindowText("number2 :");
GetDlgItem(IDC_STATIC3)->SetWindowText("Result :");
GetDlgItem(IDOK)->SetWindowText("Clear");
GetDlgItem(IDCANCEL)->SetWindowText("Exit");
GetDlgItem(IDC_add)->SetWindowText("Add");
GetDlgItem(IDC_jian)->SetWindowText("Sub");
GetDlgItem(IDC_chen)->SetWindowText("Mul");
GetDlgItem(IDC_chu)->SetWindowText("Div");
// GetDlgItem(IDD_DIALOG1)->SetWindowCaption("Simple Calculator");
}
}
void ctestdlg::OnOK()
{
char ch1[2]=" ";
// TODO: Add extra validation here
SetDlgItemText(IDC_EDIT1,ch1);
SetDlgItemText(IDC_EDIT2,ch1);
SetDlgItemText(IDC_EDIT3,ch1);
//清空文本框
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -