📄 kxdlg.cpp
字号:
// KXdlg.cpp : implementation file//written by 熊英
//
#include "stdafx.h"
#include "XYCALC.h"
#include "KXdlg.h"
#include "math.h"
#include "CountDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CKXdlg dialog
const COLORREF LTGRAY = RGB(192, 192, 192);
const COLORREF RED = RGB(255, 0, 0);
const COLORREF BLUE = RGB(0, 0, 255);
const COLORREF DKGRAY = RGB(128, 128, 128);
const COLORREF MAGENTA = RGB(255, 0, 255);
CCountDlg* g_pmodless=NULL;
CKXdlg::CKXdlg(CWnd* pParent /*=NULL*/)
: CDialog(CKXdlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CKXdlg)
m_jinzhi = 1;
m_dushu = 0;
m_inv = FALSE;
m_hyp = FALSE;
m_str = _T("");
flagjz=0;
//}}AFX_DATA_INIT
m_hAccel = LoadAccelerators(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDD));
}
void CKXdlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CKXdlg)
DDX_Radio(pDX, IDC_RADIO1, m_jinzhi);
DDX_Radio(pDX, IDC_RADIO5, m_dushu);
DDX_Check(pDX, IDC_CHECK1, m_inv);
DDX_Check(pDX, IDC_CHECK2, m_hyp);
DDX_Text(pDX, IDC_EDITKX, m_str);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CKXdlg, CDialog)
//{{AFX_MSG_MAP(CKXdlg)
ON_COMMAND(ID_MENUITEM32777, OnMenuitem32777)
ON_BN_CLICKED(IDC_BUTTON5, OnButtondivid)
ON_BN_CLICKED(IDC_BUTTON6, OnButtontime)
ON_BN_CLICKED(IDC_BUTTON7, OnButtonsub)
ON_BN_CLICKED(IDC_BUTTON8, OnButtonadd)
ON_BN_CLICKED(IDC_MOD, OnMod)
ON_BN_CLICKED(IDC_OR, OnOr)
ON_BN_CLICKED(IDC_LSH, OnLsh)
ON_BN_CLICKED(IDC_EQUAL, OnEqual)
ON_BN_CLICKED(IDC_AND, OnAnd)
ON_BN_CLICKED(IDC_XOR, OnXor)
ON_BN_CLICKED(IDC_NOT, OnNot)
ON_BN_CLICKED(IDC_INT, OnInt)
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
ON_BN_CLICKED(IDC_BUTTONPOINT, OnButtonpoint)
ON_WM_DESTROY()
ON_BN_CLICKED(IDC_BUTTON1, OnCC)
ON_BN_CLICKED(IDC_SIN, OnSin)
ON_BN_CLICKED(IDC_RADIO6, OnRadio6)
ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
ON_BN_CLICKED(IDC_RADIO7, OnRadio7)
ON_BN_CLICKED(IDC_COS, OnCos)
ON_BN_CLICKED(IDC_TAN, OnTan)
ON_BN_CLICKED(IDC_IN, OnIn)
ON_BN_CLICKED(IDC_LOG, OnLog)
ON_BN_CLICKED(IDC_FACTOR, OnFactor)
ON_BN_CLICKED(IDC_DAOSHUX, OnDaoshux)
ON_BN_CLICKED(IDC_BUTTON18, Onzhengfu)
ON_BN_CLICKED(IDC_FE, OnFe)
ON_BN_CLICKED(IDC_EXP, OnExp)
ON_BN_CLICKED(IDC_X3, OnX3)
ON_BN_CLICKED(IDC_X2, OnX2)
ON_BN_CLICKED(IDC_XY, OnXy)
ON_BN_CLICKED(IDC_PI, OnPi)
ON_BN_CLICKED(IDC_DMS, OnDms)
ON_BN_CLICKED(IDC_MC1, OnMc1)
ON_BN_CLICKED(IDC_MR1, OnMr1)
ON_BN_CLICKED(IDC_MS1, OnMs1)
ON_BN_CLICKED(IDC_MADD1, OnMadd1)
ON_BN_CLICKED(IDC_BASPACE, OnBaspace)
ON_BN_CLICKED(IDC_CHECK1, OnCheck1)
ON_BN_CLICKED(IDC_CHECK2, OnCheck2)
ON_BN_CLICKED(IDC_LEFT, OnLeft)
ON_BN_CLICKED(IDC_RIGHT, OnRight)
ON_COMMAND(ID_MENUcopy, OnMENUcopy)
ON_COMMAND(ID_MENUpaste, OnMENUpaste)
ON_COMMAND_RANGE(IDC_BUTTONA0, IDC_BUTTONA9, OnClickedNumber)
ON_COMMAND_RANGE(IDC_BUTTONA, IDC_BUTTONF, OnClickedNumberAF)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_STA, OnSta)
ON_BN_CLICKED(IDC_PAT, OnDat)
ON_BN_CLICKED(IDC_SUM, OnSum)
ON_BN_CLICKED(IDC_AVE, OnAve)
ON_WM_CANCELMODE()
ON_WM_CAPTURECHANGED()
ON_BN_CLICKED(IDC_DAT, OnDat)
ON_BN_CLICKED(IDC_S, OnS)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CKXdlg message handlers
void CKXdlg::OnMenuitem32777()
{
// TODO: Add your command handler code here
CXYCALCDlg dlg;
dlg.DoModal( );
}
BOOL CKXdlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_jinzhi=1;
//onclearkx( );
OnCC( );
colorbutton( );
clears( );
clearp( );
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CKXdlg::enablecount(bool state)
{
int i;
for(i=0;i<=12;i+=4)
{
GetDlgItem(IDC_AVE+i)->EnableWindow(state);
}
}
void CKXdlg::enablefunc(bool state)
{
int i;
for(i=0;i<=16;i=i+4)
{
GetDlgItem(IDC_FE+i)->EnableWindow(state);
}
GetDlgItem(IDC_EXP)->EnableWindow(state);
GetDlgItem(IDC_PI)->EnableWindow(state);
}
void CKXdlg::enable10(bool state)
{
int i;
for(i=0;i<10;i++)
{
GetDlgItem(IDC_BUTTONA0+i)->EnableWindow(state);
}
}
void CKXdlg::enable2(bool state)
{ int i;
for(i=0;i<8;i++)
{
GetDlgItem(IDC_BUTTONA2+i)->EnableWindow(state);
}
}
void CKXdlg::enable8(bool state)
{
int i;
for(i=0;i<2;i++)
{
GetDlgItem(IDC_BUTTONA8+i)->EnableWindow(state);
}
}
void CKXdlg::enable16(bool state)
{
/*bool bstate;
if (m_jinzhi!=0)
bstate=FALSE;
else if(m_jinzhi==0)
bstate=TRUE;*/
int i;
for(i=0;i<6;i++)
{
GetDlgItem(IDC_BUTTONA+i)->EnableWindow(state);
}
}
void CKXdlg::onclearkx()
{
m_operand = 0L;
m_operator = OpNone;
m_accum = 0L;
point=0;
bitnum=0;
left=0;
CString str;
str.Format("%s"," ");
CEdit* pedit=(CEdit *)GetDlgItem(IDC_kuohao);
pedit->SetWindowText(str);
enablecount(FALSE); //disable count
memoryvalue=0L;
m_operavail=FALSE;
m_errorState = ErrNone;
number=0;
signum=0;
m_inv=FALSE;
m_hyp=FALSE;
UpdateData(FALSE);
settext( );
updisp( );
}
void CKXdlg::turnword()
{
CString str;
unsigned long int lVal = (m_operavail) ?(unsigned long int)m_operand : (unsigned long int)m_accum;
if(m_dushu==0) //如果是双字
lVal=(unsigned long int)(lVal);
else if(m_dushu==1) //如果是字
lVal=(unsigned short)(lVal);
else if(m_dushu==2) //如果是字节
lVal=(unsigned char)(lVal);
//if (m_operavail)
m_operand=lVal;
//else
m_accum=lVal;
}
void CKXdlg::disp2()
{
turnword( );
CString str1("");
CString str2;
unsigned long int lVal = (m_operavail) ?(unsigned long int) m_operand : (unsigned long int)m_accum;
unsigned long int a=lVal;
while((a/2)!=0)
{
str2.Format("%d",a%2);
str1.Insert(0,str2);
a=a/2;
}
str2.Format("%d",a);
str1.Insert(0,str2);
CEdit* pedit=(CEdit *)GetDlgItem(IDC_EDITKX);
pedit->SetWindowText(str1);
m_str=str1;
}
void CKXdlg::disp8()
{
turnword( );
CString str;
unsigned long int lVal = (m_operavail) ?(unsigned long int) m_operand :(unsigned long int) m_accum;
str.Format("%o",(lVal));
CEdit* pedit=(CEdit *)GetDlgItem(IDC_EDITKX);
pedit->SetWindowText(str);
m_str=str;
}
void CKXdlg::disp16()
{
turnword( );
CString str;
unsigned long int lVal = (m_operavail) ?(unsigned long int) m_operand :(unsigned long int) m_accum;
str.Format("%x",(lVal));
CEdit* pedit=(CEdit *)GetDlgItem(IDC_EDITKX);
pedit->SetWindowText(str);
m_str=str;
}
void CKXdlg::updisp()
{
if (m_jinzhi!=1)
{
if(m_jinzhi==0)// 将结果由十进制转化为16进制
{ disp16( );
}
else if(m_jinzhi==2)// 将结果由十进制转化为8进制
{ disp8( );
}
else if(m_jinzhi==3)// 将结果由十进制转化为二进制
{
disp2( );
}
}
else //十进制的显示,fe是科学记数法
if(m_jinzhi==1)
{
double lVal = (m_operavail) ? m_operand : m_accum;
CString str;
if((!fe)||(lVal>1.0e+30))
{ str.Format(_T("%e"),lVal);
int i=str.GetLength( );
// if(str.GetAt(i-1)=='0')
// str.Delete(i-2,2);
}
else
{ str.Format(_T("%f"),lVal);
int i=str.GetLength( );
while(str.GetAt(i-1)=='0')
{
str.Delete(i-1,1);
i-=1;
}
}
CEdit* pedit=(CEdit *)GetDlgItem(IDC_EDITKX);
pedit->SetWindowText(str);
m_str=str;
}
}
void CKXdlg::input(int l,int lm)
{
if(m_dushu==0)
{ double a;
a=m_operand*l+lm;
if( a<=4294967295)
setoperand(a);
}
if(m_dushu==1)
{ double a;
a=m_operand*l+lm;
if( a<=65535)
setoperand(a);
}
if (m_dushu==2)
{ double a;
a=m_operand*l+lm;
if( a<=255)
setoperand(a);
}
}
void CKXdlg::clicknumber(int lm) //输入数字
{
if (!m_operavail)
{m_operand = 0L;
point=0;
bitnum=0;
}
if (point==1)
{ bitnum++;
if(m_jinzhi==0)
input(16,lm);
else if(m_jinzhi==1)
setoperand(m_operand+lm/pow(10,bitnum));
else if(m_jinzhi==2)
input(8,lm);
else
input(2,lm);
}
else
{if(m_jinzhi==0)
input(16,lm);
else if(m_jinzhi==1)
setoperand(m_operand*10+lm);
else if(m_jinzhi==2)
input(8,lm);
else if(m_jinzhi==3)
input(2,lm);
}
updisp();
}
void CKXdlg::ClickNumberAF(int n)//输入数字A ....F
{
if (!m_operavail)
{m_operand = 0L;
point=0;
bitnum=0;
}
if(m_jinzhi==0)
input(16,n+10);
updisp();
}
void CKXdlg::OnClickedNumber(UINT nID)
{
ASSERT(nID >= IDC_BUTTONA0 && nID <= IDC_BUTTONA9);
clicknumber(nID - IDC_BUTTONA0);
}
void CKXdlg::OnClickedNumberAF(UINT nID)
{
ASSERT(nID >= IDC_BUTTONA && nID <= IDC_BUTTONF);
ClickNumberAF(nID - IDC_BUTTONA);
}
void CKXdlg::OnButtondivid()
{
// TODO: Add your control notification handler code here
m_operator=OpDivide;
m_operavail=FALSE;
run( );//pushfh( );
}
void CKXdlg::OnButtontime()
{
// TODO: Add your control notification handler code here
m_operator=OpMultiply;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnButtonsub()
{
// TODO: Add your control notification handler code here
m_operator=OpSubtract;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnButtonadd()
{
// TODO: Add your control notification handler code here
m_operator=OpAdd;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnLeft()
{
// TODO: Add your control notification handler code here
left++;
CString str;
str.Format("%s%d","(=",left);
CEdit* pedit=(CEdit *)GetDlgItem(IDC_kuohao);
pedit->SetWindowText(str);
m_operator=OpLeft;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnRight()
{
// TODO: Add your control notification handler code here
m_operator=OpRight;
m_operavail=FALSE;
CString str;
left--;
if (left)
str.Format("%s%d","(=",left);
else
str.Format("%s"," ");
CEdit* pedit=(CEdit *)GetDlgItem(IDC_kuohao);
pedit->SetWindowText(str);
// pushfh( );
enters(m_operand);
Operator op;
while(p.peek( )!=OpLeft)
{
op=p.pop( );
computer(op);
}
m_operand=m_accum=s.peek( );
updisp( );
p.pop( );
s.pop( );
}
void CKXdlg::OnMod()
{
// TODO: Add your control notification handler code here
m_operator=OpMod;
m_operavail=FALSE;
run( ); // pushfh( );
}
void CKXdlg::OnOr()
{
// TODO: Add your control notification handler code here
m_operator=OpOr;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnLsh()
{
// TODO: Add your control notification handler code here
m_operator=OpLsh;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnEqual()
{
// TODO: Add your control notification handler code here
m_operator=OpNone;
m_operavail=FALSE;
run( );// pushfh( );
}
void CKXdlg::OnAnd()
{
// TODO: Add your control notification handler code here
m_operator=OpAnd;
m_operavail=FALSE;
run();// pushfh( );
}
void CKXdlg::OnXor()
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -