From e00d5a1575d26f8fec1be6fa8a844203cd66a24c Mon Sep 17 00:00:00 2001
From: Yao Chunli <56721587@qq.com>
Date: 星期二, 21 六月 2022 16:11:11 +0800
Subject: [PATCH] edit input key

---
 MTerm2/DialogFactCfg.cpp |  108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 108 insertions(+), 0 deletions(-)

diff --git a/MTerm2/DialogFactCfg.cpp b/MTerm2/DialogFactCfg.cpp
index ad10b8f..51f56ad 100644
--- a/MTerm2/DialogFactCfg.cpp
+++ b/MTerm2/DialogFactCfg.cpp
@@ -33,6 +33,19 @@
 	ON_BN_CLICKED(IDC_BUTTON_DISCONN, &CDialogFactCfg::OnBnClickedButtonDisconn)
 	ON_BN_CLICKED(IDC_BUTTON_READDATA, &CDialogFactCfg::OnBnClickedButtonReaddata)
 	ON_BN_CLICKED(IDC_BUTTON_WRITEDATA, &CDialogFactCfg::OnBnClickedButtonWritedata)
+
+	ON_BN_CLICKED(IDC_BUTTON1, &CDialogFactCfg::OnBnClickedBtn1)
+	ON_BN_CLICKED(IDC_BUTTON3, &CDialogFactCfg::OnBnClickedBtn3)
+	ON_BN_CLICKED(IDC_BUTTON4, &CDialogFactCfg::OnBnClickedBtn4)
+	ON_BN_CLICKED(IDC_BUTTON5, &CDialogFactCfg::OnBnClickedBtn5)
+	ON_BN_CLICKED(IDC_BUTTON_CLEAR, &CDialogFactCfg::OnBnClickedBtnClear)
+	ON_BN_CLICKED(IDC_BUTTON_ADD, &CDialogFactCfg::OnBnClickedBtnAdd)
+	ON_BN_CLICKED(IDC_BUTTON_BACKSPACE, &CDialogFactCfg::OnBnClickedBtnBackSpace)
+
+
+	ON_BN_CLICKED(IDC_BUTTON_0, &CDialogFactCfg::OnBnClickedButton0)
+	ON_BN_CLICKED(IDC_BUTTON1_DOT, &CDialogFactCfg::OnBnClickedButton1Dot)
+	ON_BN_CLICKED(IDC_BUTTON_EQ, &CDialogFactCfg::OnBnClickedButtonEq)
 END_MESSAGE_MAP()
 
 // CDialogFactCfg 娑堟伅澶勭悊绋嬪簭
@@ -600,3 +613,98 @@
 
 }
 
+CString saveInputStr=_T(""), saveInput1Str= _T("");
+CString sDisplayStr;
+CString sStoreStr;
+bool bEditEndFlg = false;
+
+int CDialogFactCfg::CharKeyClick(CString sKey)
+{
+	// TODO: 鍦ㄦ澶勬坊鍔犲疄鐜颁唬鐮�.
+	if (bEditEndFlg)
+	{
+		sDisplayStr.Empty();
+		bEditEndFlg = false;
+	}
+	sDisplayStr.Append(sKey);
+	int len1 = sDisplayStr.GetLength();
+	if (len1 > 1 && sDisplayStr[0] == _T('0')) sDisplayStr = sDisplayStr.Right(sDisplayStr.GetLength() - 1);
+
+	SetDlgItemText(IDC_EDIT_VIEW, sDisplayStr);
+	return 0;
+}
+void CDialogFactCfg::OnBnClickedBtn1()
+{
+	CharKeyClick(_T("1"));
+}
+void CDialogFactCfg::OnBnClickedBtn3()
+{
+	CharKeyClick(_T("3"));
+}
+void CDialogFactCfg::OnBnClickedBtn4()
+{
+	CharKeyClick(_T("4"));
+}
+void CDialogFactCfg::OnBnClickedBtn5() 
+{
+	CharKeyClick(_T("5"));
+}
+void CDialogFactCfg::OnBnClickedBtnClear()
+{
+	sDisplayStr.Empty();
+	bEditEndFlg = false;
+	SetDlgItemText(IDC_EDIT_VIEW, _T("0"));
+}
+void CDialogFactCfg::OnBnClickedBtnAdd() 
+{
+	bEditEndFlg = true;
+	sStoreStr = sDisplayStr;
+
+	//saveInput1Str = saveInputStr;
+	//saveInputStr = "";
+}
+void CDialogFactCfg::OnBnClickedBtnBackSpace()
+{
+	int len1 = sDisplayStr.GetLength();
+	if (len1 > 1)
+	{
+		sDisplayStr = sDisplayStr.Left(sDisplayStr.GetLength() - 1);
+	}
+	else if (len1 == 1)
+	{
+		sDisplayStr = "0";
+	}
+//	bEditEndFlg = false;
+	SetDlgItemText(IDC_EDIT_VIEW, sDisplayStr);
+}
+
+
+
+void CDialogFactCfg::OnBnClickedButton0()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	CharKeyClick(_T("0"));
+}
+
+
+void CDialogFactCfg::OnBnClickedButton1Dot()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	CharKeyClick(_T("."));
+}
+
+
+void CDialogFactCfg::OnBnClickedButtonEq()
+{
+	// TODO: 鍦ㄦ娣诲姞鎺т欢閫氱煡澶勭悊绋嬪簭浠g爜
+	bEditEndFlg = true;
+
+	float a = _tstof(sStoreStr);
+	float b = _tstof(sDisplayStr);
+
+	float c = a + b;
+
+	sDisplayStr.Format(_T("%g"),c);
+	SetDlgItemText(IDC_EDIT_VIEW, sDisplayStr);
+
+}

--
Gitblit v1.9.1