📄 复数计算器dlg.cpp
字号:
// 复数计算器Dlg.cpp : implementation file
//
#include "stdafx.h"
#include <complex>
#include "复数计算器.h"
#include "复数计算器Dlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMyDlg)
m_ResultReal = 0.0;
m_ResultImag = 0.0;
m_MonReal = 0.0;
m_MonImag = 0.0;
m_BinFstImag = 0.0;
m_BinSecImag = 0.0;
m_BinFstReal = 0.0;
m_BinSecReal = 0.0;
m_X = 0.0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Text(pDX, IDC_RESULT_REAL, m_ResultReal);
DDX_Text(pDX, IDC_RESULT_IMAG, m_ResultImag);
DDX_Text(pDX, IDC_EDIT_MON_REAL, m_MonReal);
DDX_Text(pDX, IDC_EDIT_MON_IMAG, m_MonImag);
DDX_Text(pDX, IDC_EDIT_BIN_IMAG1, m_BinFstImag);
DDX_Text(pDX, IDC_EDIT_BIN_IMAG2, m_BinSecImag);
DDX_Text(pDX, IDC_EDIT_BIN_REAL1, m_BinFstReal);
DDX_Text(pDX, IDC_EDIT_BIN_REAL2, m_BinSecReal);
DDX_Text(pDX, IDC_EDIT_X, m_X);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON_POW, OnButtonPow)
ON_BN_CLICKED(IDC_BUTTON_SQRT, OnButtonSqrt)
ON_BN_CLICKED(IDC_BUTTON_PLUS, OnButtonPlus)
ON_BN_CLICKED(IDC_BUTTON_MINUS, OnButtonMinus)
ON_BN_CLICKED(IDC_BUTTON_MULTIPLY, OnButtonMultiply)
ON_BN_CLICKED(IDC_BUTTON_DIVIDE, OnButtonDivide)
ON_BN_CLICKED(IDC_RADIO_MONADIC, OnRadioMonadic)
ON_BN_CLICKED(IDC_RADIO_BINARY, OnRadioBinary)
ON_BN_CLICKED(IDC_BUTTON_EXP, OnButtonExp)
ON_BN_CLICKED(IDC_BUTTON_LOG, OnButtonLog)
ON_BN_CLICKED(IDC_BUTTON_SIN, OnButtonSin)
ON_BN_CLICKED(IDC_BUTTON_COS, OnButtonCos)
ON_BN_CLICKED(IDC_BUTTON_TAN, OnButtonTan)
ON_BN_CLICKED(IDC_BUTTON_SINH, OnButtonSinh)
ON_BN_CLICKED(IDC_BUTTON_COSH, OnButtonCosh)
ON_BN_CLICKED(IDC_BUTTON_TANH, OnButtonTanh)
ON_BN_CLICKED(IDC_BUTTON_POWX, OnButtonPowx)
ON_BN_CLICKED(IDC_BUTTON_POWZ, OnButtonPowz)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
((CButton*)(GetDlgItem(IDC_RADIO_MONADIC)))->SetCheck(1);
GetDlgItem(IDC_EDIT_BIN_REAL1)->EnableWindow(false);
GetDlgItem(IDC_EDIT_BIN_IMAG1)->EnableWindow(false);
GetDlgItem(IDC_EDIT_BIN_REAL2)->EnableWindow(false);
GetDlgItem(IDC_EDIT_BIN_IMAG2)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_PLUS)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_MINUS)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_MULTIPLY)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_DIVIDE)->EnableWindow(false);
// m_ctlRadioMonadic.SetCheck(BS_CHECKBOX);//Create(BS_RADIOBUTTON,IDC_RADIO_MONADIC)
return TRUE; // return TRUE unless you set the focus to a control
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CMyDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnButtonPow()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag);
m_ResultReal=(X*X).real();
m_ResultImag=(X*X).imag();
UpdateData(false);
}
void CMyDlg::OnButtonSqrt()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag);
m_ResultReal=std::sqrt(X).real();
m_ResultImag=std::sqrt(X).imag();
UpdateData(false);
}
void CMyDlg::OnButtonPlus()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X1(m_BinFstReal,m_BinFstImag),X2(m_BinSecReal,m_BinSecImag);
m_ResultReal=X1.real()+X2.real();
m_ResultImag=X1.imag()+X2.imag();
UpdateData(false);
}
void CMyDlg::OnButtonMinus()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X1(m_BinFstReal,m_BinFstImag),X2(m_BinSecReal,m_BinSecImag);
m_ResultReal=X1.real()-X2.real();
m_ResultImag=X1.imag()-X2.imag();
UpdateData(false);
}
void CMyDlg::OnButtonMultiply()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X1(m_BinFstReal,m_BinFstImag),X2(m_BinSecReal,m_BinSecImag),Xr;
Xr=X1*X2;
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonDivide()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X1(m_BinFstReal,m_BinFstImag),X2(m_BinSecReal,m_BinSecImag),Xr;
if(m_BinSecImag!=m_BinSecReal!=0)
{
Xr=X1/X2;
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
}
else AfxMessageBox("除数为零");
UpdateData(false);
}
void CMyDlg::OnRadioMonadic()
{
// TODO: Add your control notification handler code here
// m_ctlRadioMonadic.SetCheck(BST_CHECKED);
//
// IsDlgButtonChecked(IDC_CHECK1)
//(CEdit*)GetDlgItem(IDC_EDIT_MON_REAL)->
GetDlgItem(IDC_EDIT_BIN_REAL1)->EnableWindow(false);
GetDlgItem(IDC_EDIT_BIN_IMAG1)->EnableWindow(false);
GetDlgItem(IDC_EDIT_BIN_REAL2)->EnableWindow(false);
GetDlgItem(IDC_EDIT_BIN_IMAG2)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_PLUS)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_MINUS)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_MULTIPLY)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_DIVIDE)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_POWZ)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_POWX)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_TANH)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_COSH)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_SINH)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_TAN)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_COS)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_SIN)->EnableWindow(true);
GetDlgItem(IDC_EDIT_X)->EnableWindow(true);
GetDlgItem(IDC_EDIT_MON_REAL)->EnableWindow(true);
GetDlgItem(IDC_EDIT_MON_IMAG)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_POW)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_SQRT)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_EXP)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_LOG)->EnableWindow(true);
}
void CMyDlg::OnRadioBinary()
{
// TODO: Add your control notification handler code here
((CButton*)(GetDlgItem(IDC_RADIO_MONADIC)))->SetCheck(0);
GetDlgItem(IDC_EDIT_BIN_REAL1)->EnableWindow(true);
GetDlgItem(IDC_EDIT_BIN_IMAG1)->EnableWindow(true);
GetDlgItem(IDC_EDIT_BIN_REAL2)->EnableWindow(true);
GetDlgItem(IDC_EDIT_BIN_IMAG2)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_PLUS)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_MINUS)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_MULTIPLY)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_DIVIDE)->EnableWindow(true);
GetDlgItem(IDC_BUTTON_POWZ)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_POWX)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_TANH)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_COSH)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_SINH)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_TAN)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_COS)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_SIN)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_LOG)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_EXP)->EnableWindow(false);
GetDlgItem(IDC_EDIT_X)->EnableWindow(false);
GetDlgItem(IDC_EDIT_MON_REAL)->EnableWindow(false);
GetDlgItem(IDC_EDIT_MON_IMAG)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_POW)->EnableWindow(false);
GetDlgItem(IDC_BUTTON_SQRT)->EnableWindow(false);
}
void CMyDlg::OnButtonExp()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=std::exp(X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonLog()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
if(m_MonReal!=m_MonImag!=0)
{
Xr=std::log(X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
}
else AfxMessageBox("零值没有对数");
UpdateData(false);
}
void CMyDlg::OnButtonSin()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=std::sin(X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonCos()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=std::cos(X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonTan()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=(std::sin(X))/(std::cos(X));
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonSinh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=std::sinh(X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonCosh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=std::cosh(X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonTanh()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xr;
Xr=(std::sinh(X))/(std::cosh(X));
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonPowx()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xi(m_X,0),Xr;
Xr=std::pow(X,Xi);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
void CMyDlg::OnButtonPowz()
{
// TODO: Add your control notification handler code here
UpdateData(true);
std::complex<double> X(m_MonReal,m_MonImag),Xi(m_X,0),Xr;
Xr=std::pow(Xi,X);
m_ResultReal=Xr.real();
m_ResultImag=Xr.imag();
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -