📄 longjsqdlg.cpp
字号:
// LongJSQDlg.cpp : implementation file
//
#include "stdafx.h"
#include "LongJSQ.h"
#include "LongJSQDlg.h"
#include "WBButton.h"//lzf add
#include "BignumClass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLongJSQDlg dialog
CLongJSQDlg::CLongJSQDlg(CWnd* pParent /*=NULL*/)
: CDialog(CLongJSQDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CLongJSQDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CLongJSQDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CLongJSQDlg)
DDX_Control(pDX, IDC_X, m_x);
DDX_Control(pDX, IDC_COMPART, m_compart);
DDX_Control(pDX, IDC_S, m_s);
DDX_Control(pDX, IDC_P, m_p);
DDX_Control(pDX, IDC_II, m_ii);
DDX_Control(pDX, IDC_C, m_c);
DDX_Control(pDX, IDC_0,m_num0);
DDX_Control(pDX, IDC_1,m_num1);
DDX_Control(pDX, IDC_2,m_num2);
DDX_Control(pDX, IDC_3,m_num3);
DDX_Control(pDX, IDC_4,m_num4);
DDX_Control(pDX, IDC_5,m_num5);
DDX_Control(pDX, IDC_6,m_num6);
DDX_Control(pDX, IDC_7,m_num7);
DDX_Control(pDX, IDC_8,m_num8);
DDX_Control(pDX, IDC_9,m_num9);
DDX_Control(pDX, IDC_POINT,m_point);
DDX_Control(pDX, IDC_ADD,m_add);
DDX_Control(pDX, IDC_SUB ,m_sub);
DDX_Control(pDX, IDC_MUL ,m_mul);
DDX_Control(pDX, IDC_DIV ,m_div);
DDX_Control(pDX, IDC_POW ,m_pow);
DDX_Control(pDX, IDC_FACTORIAL,m_factorial);
DDX_Control(pDX, IDC_LEFT_PARENTHESES,m_left_parentheses);
DDX_Control(pDX, IDC_RIGHT_PARENTHESES,m_right_parentheses);
DDX_Control(pDX, IDC_LEFT_ABS,m_left_abs);
DDX_Control(pDX, IDC_RIGHT_ABS,m_right_abs);
DDX_Control(pDX, IDC_EQUAL,m_equal);
DDX_Control(pDX, IDC_BACK,m_back);
DDX_Control(pDX, IDC_OFF ,m_off);
DDX_Control(pDX, IDC_SHOW_EDIT, m_show_edit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CLongJSQDlg, CDialog)
//{{AFX_MSG_MAP(CLongJSQDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CONTROL_RANGE(BN_CLICKED,IDC_0,IDC_RIGHT_ABS,OnBnNum)//lzf add
ON_BN_CLICKED(IDC_BACK, OnBack)
ON_BN_CLICKED(IDC_OFF, OnOff)
ON_BN_CLICKED(IDC_EQUAL, OnSlove)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CLongJSQDlg message handlers
BOOL CLongJSQDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
m_s.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_p.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_ii.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_c.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num0.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num1.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num2.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num3.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num4.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num5.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num6.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num7.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num8.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_num9.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_point.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_add.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_sub.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_mul.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_div.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_pow.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_factorial.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_left_parentheses.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_right_parentheses.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_left_abs.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_right_abs.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_equal.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_back.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_off.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_compart.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
m_x.LoadBitmaps(IDB_BITMAP1,5, 5, 5, 5, 4 );
return TRUE; // return TRUE unless you set the focus to a control
}
void CLongJSQDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CLongJSQDlg::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
{
//lzf add //设置背景色
CPaintDC dc(this);
CRect ClientRect;
GetClientRect(ClientRect);
CBrush bkBrush(RGB(160,180,220));//设置背景色的刷子
//SetDialogBkColor(RGB(255,0,0),RGB(0,255,0));
dc.FillRect(ClientRect,&bkBrush);
//lzf add end
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CLongJSQDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CLongJSQDlg::OnBnNum(UINT nID) //
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
switch(nID)
{
case IDC_0 : m_show_edit.ReplaceSel("0");break;
case IDC_1 : m_show_edit.ReplaceSel("1");break;
case IDC_2 : m_show_edit.ReplaceSel("2");break;
case IDC_3 : m_show_edit.ReplaceSel("3");break;
case IDC_4 : m_show_edit.ReplaceSel("4");break;
case IDC_5 : m_show_edit.ReplaceSel("5");break;
case IDC_6 : m_show_edit.ReplaceSel("6");break;
case IDC_7 : m_show_edit.ReplaceSel("7");break;
case IDC_8 : m_show_edit.ReplaceSel("8");break;
case IDC_9 : m_show_edit.ReplaceSel("9");break;
case IDC_POINT : m_show_edit.ReplaceSel(".");break;
case IDC_ADD : m_show_edit.ReplaceSel("+");break;
case IDC_SUB : m_show_edit.ReplaceSel("-");break;
case IDC_MUL : m_show_edit.ReplaceSel("*");break;
case IDC_DIV : m_show_edit.ReplaceSel("/");break;
case IDC_COMPART : m_show_edit.ReplaceSel(",");break;
case IDC_S : m_show_edit.ReplaceSel("S");break;
case IDC_P : m_show_edit.ReplaceSel("P");break;
case IDC_C : m_show_edit.ReplaceSel("C");break;
case IDC_POW : m_show_edit.ReplaceSel("^");break;
case IDC_FACTORIAL : m_show_edit.ReplaceSel("!");break;
case IDC_II : m_show_edit.ReplaceSel("II");break;
case IDC_LEFT_PARENTHESES : m_show_edit.ReplaceSel("(");break;
case IDC_RIGHT_PARENTHESES : m_show_edit.ReplaceSel(")");break;
case IDC_LEFT_ABS : m_show_edit.ReplaceSel("[");break;
case IDC_RIGHT_ABS : m_show_edit.ReplaceSel("]");break;
default : break;
}
}
void CLongJSQDlg::OnBack()
{
// TODO: Add your control notification handler code here
CString str;
int index;
m_show_edit.GetWindowText(str);
index=str.GetLength();
str=str.Left(index-1);
m_show_edit.SetSel(0,-1);
m_show_edit.ReplaceSel(str);
}
void CLongJSQDlg::OnOff()
{
// TODO: Add your control notification handler code here
m_show_edit.SetSel(0,-1);
m_show_edit.ReplaceSel("");
}
void CLongJSQDlg::OnSlove()
{
// TODO: Add your control notification handler code here
m_show_edit.ReplaceSel("=");
char char_edit[10000];
char char_result[MAX];
m_show_edit.GetWindowText(char_edit,10000);
BignumClass str_def1( char_edit) ;
str_def1.translate_char();
str_def1.slove ();
int i=0;
int p=MAX*2/3-str_def1.head->nArray [0]+1;
if(str_def1.head->nArray [p]<0)//若是负数,
{
char_result[i++]='-';
char_result[i++]=-1*str_def1.head->nArray [p]+48;
p=p+1;
}
for(;p<=MAX*2/3+str_def1.head->nArray [MAX-1];p++)
{
if(p==MAX*2/3+1) char_result[i++]='.';
char_result[i++]=str_def1.head->nArray [p]+48;//把数字用字符表示
}
char_result[i++]='\0';
int nLen=m_show_edit.GetWindowTextLength ();
m_show_edit.SetFocus ();
m_show_edit.SetSel (nLen, nLen);
m_show_edit.ReplaceSel (char_result);
}
//捕获键盘按键的消息
BOOL CLongJSQDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message==WM_CHAR&&pMsg->wParam==VK_RETURN)
OnSlove();
//if(pMsg->message==WM_CHAR&&pMsg->wParam==VK_=)//是等号时
// OnSlove();
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -