From 6ff05a44b01c6ac6e33db2ec28dcf6e2a7c2abb0 Mon Sep 17 00:00:00 2001
From: QuakeGod <quakegod@sina.com>
Date: 星期二, 16 一月 2024 19:46:01 +0800
Subject: [PATCH] fix LDS to Prog

---
 MTerm1/MTerm1.cpp |  235 ++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 177 insertions(+), 58 deletions(-)

diff --git a/MTerm1/MTerm1.cpp b/MTerm1/MTerm1.cpp
index bd9935e..e8548a5 100644
--- a/MTerm1/MTerm1.cpp
+++ b/MTerm1/MTerm1.cpp
@@ -12,6 +12,20 @@
 #include "ChildFrm.h"
 #include "MTerm1Doc.h"
 #include "MTerm1View.h"
+#include "MTerm1LdsView.h"
+#include "MTerm1BldView.h"
+#include "MTerm1BnlView.h"
+
+#include "MTerm1CoilView.h"
+#include "MTerm1DataView.h"
+
+#include "MTerm1TestView.h"
+#include "MTerm1CtrlView.h"
+#include "MTerm1ProgTxt.h"
+
+
+
+#include "MTerm1CommDevView.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -19,20 +33,22 @@
 
 #include <devguid.h>
 #include <SetupAPI.h>
+//#include "HvSerialPort.h"
+//#include "CAnsiParser.h"
+//#include "CDataParser1.h"
+//#include "KLink.h"
 
 #include <eh.h>
 #include <dbghelp.h>
 #pragma comment(lib,"dbghelp.lib")
-
-#pragma comment(lib,"gdiplus.lib")
 #pragma comment(lib,"SetupAPI.lib")
+#pragma comment(lib,"gdiplus.lib")
 
+#include "../KLink1/KLink.h"
+
+#pragma comment(lib,"KLink1.lib")
 MHash MyCfg1;
-Logger MyLogger1;
-
-//KLinkProtocol MyKLProtocol1;
-// CSerialCom MySerialCom1;
-//HvSerialPort MyHvSerialPort1;
+Logger myLogger1;
 
 // CMTerm1App
 
@@ -44,6 +60,8 @@
 	ON_COMMAND(ID_FILE_OPEN, &CWinAppEx::OnFileOpen)
 	// 鏍囧噯鎵撳嵃璁剧疆鍛戒护
 	ON_COMMAND(ID_FILE_PRINT_SETUP, &CWinAppEx::OnFilePrintSetup)
+//	ON_COMMAND(ID_COMUNICATION_SET, &CMTerm1App::OnComunicationSet)
+	ON_COMMAND(ID_ENV_SET, &CMTerm1App::OnEnvSet)
 END_MESSAGE_MAP()
 
 
@@ -52,7 +70,6 @@
 CMTerm1App::CMTerm1App() noexcept
 {
 	m_bHiColorIcons = TRUE;
-
 	// 鏀寔閲嶆柊鍚姩绠$悊鍣�
 	m_dwRestartManagerSupportFlags = AFX_RESTART_MANAGER_SUPPORT_ALL_ASPECTS;
 #ifdef _MANAGED
@@ -64,7 +81,7 @@
 
 	// TODO: 灏嗕互涓嬪簲鐢ㄧ▼搴� ID 瀛楃涓叉浛鎹负鍞竴鐨� ID 瀛楃涓诧紱寤鸿鐨勫瓧绗︿覆鏍煎紡
 	//涓� CompanyName.ProductName.SubProduct.VersionInformation
-	SetAppID(_T("MTerm1.AppID.NoVersion"));
+	SetAppID(_T("MultiTerminal2.AppID.NoVersion"));
 
 	// TODO: 鍦ㄦ澶勬坊鍔犳瀯閫犱唬鐮侊紝
 	// 灏嗘墍鏈夐噸瑕佺殑鍒濆鍖栨斁缃湪 InitInstance 涓�
@@ -91,6 +108,11 @@
 
 	CWinAppEx::InitInstance();
 
+	if (!AfxSocketInit())
+	{
+		AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
+		return FALSE;
+	}
 
 	// 鍒濆鍖� OLE 搴�
 	if (!AfxOleInit())
@@ -99,15 +121,12 @@
 		return FALSE;
 	}
 
-	Gdiplus::GdiplusStartupInput gdiplusStartupInput;
-	Gdiplus::GdiplusStartup(&m_gdiplusToken, &gdiplusStartupInput, NULL);
-
 	AfxEnableControlContainer();
 
-	EnableTaskbarInteraction();
+	EnableTaskbarInteraction(FALSE);
 
 	// 浣跨敤 RichEdit 鎺т欢闇�瑕� AfxInitRichEdit2()
-	// AfxInitRichEdit2();
+	 AfxInitRichEdit2();
 
 	// 鏍囧噯鍒濆鍖�
 	// 濡傛灉鏈娇鐢ㄨ繖浜涘姛鑳藉苟甯屾湜鍑忓皬
@@ -120,19 +139,9 @@
 	LoadStdProfileSettings(4);  // 鍔犺浇鏍囧噯 INI 鏂囦欢閫夐」(鍖呮嫭 MRU)
 
 
-	InitContextMenuManager();
-
-	InitKeyboardManager();
-
-	InitTooltipManager();
-	CMFCToolTipInfo ttParams;
-	ttParams.m_bVislManagerTheme = TRUE;
-	theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
-		RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
-
 	// 娉ㄥ唽搴旂敤绋嬪簭鐨勬枃妗fā鏉裤��  鏂囨。妯℃澘
 	// 灏嗙敤浣滄枃妗c�佹鏋剁獥鍙e拰瑙嗗浘涔嬮棿鐨勮繛鎺�
-	CMultiDocTemplate* pDocTemplate;
+//	CMultiDocTemplate* pDocTemplate;
 	pDocTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
 		RUNTIME_CLASS(CMTerm1Doc),
 		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
@@ -140,7 +149,86 @@
 	if (!pDocTemplate)
 		return FALSE;
 	AddDocTemplate(pDocTemplate);
+///*
+//	CMultiDocTemplate * m_pNewDocTemplate;
+///*
+	m_pLdsViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1LdsView));
+	if (!m_pLdsViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pLdsViewTemplate);
 
+	m_pBldViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1BldView));
+	if (!m_pBldViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pBldViewTemplate);
+
+	m_pBnlViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1BnlView));
+	if (!m_pBnlViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pBnlViewTemplate);
+
+	m_pCommDevViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1CommDevView));
+	if (!m_pCommDevViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pCommDevViewTemplate);
+
+
+	m_pCtrlViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1CtrlView));
+	if (!m_pCtrlViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pCtrlViewTemplate);
+
+	m_pProgViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1ProgTxt));
+	if (!m_pProgViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pProgViewTemplate);
+
+	m_pCoilViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1CoilView));
+	if (!m_pCoilViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pCoilViewTemplate);
+
+	m_pDataViewTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1DataView));
+	if (!m_pDataViewTemplate)
+		return FALSE;
+	AddDocTemplate(m_pDataViewTemplate);
+
+
+
+
+
+	m_pNewDocTemplate = new CMultiDocTemplate(IDR_MTerm1TYPE,
+		RUNTIME_CLASS(CMTerm1Doc),
+		RUNTIME_CLASS(CChildFrame), // 鑷畾涔� MDI 瀛愭鏋�
+		RUNTIME_CLASS(CMTerm1TestView));
+	if (!m_pNewDocTemplate)
+		return FALSE;
+	AddDocTemplate(m_pNewDocTemplate);
+//*/
 	// 鍒涘缓涓� MDI 妗嗘灦绐楀彛
 	CMainFrame* pMainFrame = new CMainFrame;
 	if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
@@ -155,7 +243,8 @@
 	CCommandLineInfo cmdInfo;
 	ParseCommandLine(cmdInfo);
 
-
+	if (cmdInfo.m_nShellCommand == CCommandLineInfo::FileNew)
+		cmdInfo.m_nShellCommand = CCommandLineInfo::FileNothing;
 
 	// 璋冨害鍦ㄥ懡浠よ涓寚瀹氱殑鍛戒护銆�  濡傛灉
 	// 鐢� /RegServer銆�/Register銆�/Unregserver 鎴� /Unregister 鍚姩搴旂敤绋嬪簭锛屽垯杩斿洖 FALSE銆�
@@ -164,18 +253,14 @@
 	// 涓荤獥鍙e凡鍒濆鍖栵紝鍥犳鏄剧ず瀹冨苟瀵瑰叾杩涜鏇存柊
 	pMainFrame->ShowWindow(m_nCmdShow);
 	pMainFrame->UpdateWindow();
-
 	return TRUE;
 }
 
 int CMTerm1App::ExitInstance()
 {
 	//TODO: 澶勭悊鍙兘宸叉坊鍔犵殑闄勫姞璧勬簮
-	Gdiplus::GdiplusShutdown(m_gdiplusToken);
-//	CoUninitialize();
-	SaveMyConfig();
-
 	AfxOleTerm(FALSE);
+	//this->CleanState();
 
 	return CWinAppEx::ExitInstance();
 }
@@ -222,34 +307,39 @@
 	aboutDlg.DoModal();
 }
 
-// CMTerm1App 鑷畾涔夊姞杞�/淇濆瓨鏂规硶
-
-void CMTerm1App::PreLoadState()
-{
-	BOOL bNameValid;
-	CString strName;
-	bNameValid = strName.LoadString(IDS_EDIT_MENU);
-	ASSERT(bNameValid);
-	GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EDIT);
-	bNameValid = strName.LoadString(IDS_EXPLORER);
-	ASSERT(bNameValid);
-	GetContextMenuManager()->AddMenu(strName, IDR_POPUP_EXPLORER);
-}
-
-void CMTerm1App::LoadCustomState()
-{
-}
-
-void CMTerm1App::SaveCustomState()
-{
-}
-
 // CMTerm1App 娑堟伅澶勭悊绋嬪簭
+
+void CMTerm1App::OnFileNew()
+{
+	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+	POSITION ps = m_pDocManager->GetFirstDocTemplatePosition();
+	CDocTemplate *pDocTemplate = m_pDocManager->GetNextDocTemplate(ps);
+	pDocTemplate->OpenDocumentFile(NULL);
+}
+
+
+
+void CMTerm1App::OnComunicationSet()
+{
+	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+}
+
+
+void CMTerm1App::OnEnvSet()
+{
+	// TODO: 鍦ㄦ娣诲姞鍛戒护澶勭悊绋嬪簭浠g爜
+}
 
 
 int SysLog(CString s, int channel)
 {
-	MyLogger1.LogTxt(s, channel);
+	myLogger1.LogTxt(s, channel);
+	return 1;
+}
+
+int DbgLog(CString s, int channel)
+{
+	myLogger1.LogTxt(s, channel);
 	return 1;
 }
 
@@ -486,10 +576,18 @@
 	return res;
 }
 
-CString & intToString(int num)
+CString intToString(int num, int digit)
 {
 	static CString Str1;
-	Str1.Format(_T("%d"), num);
+	if (digit != 0) {
+		CString str2;
+		str2.Format(_T("%%%dd"), digit);
+		Str1.Format(str2, num);
+
+	}else {
+		Str1.Format(_T("%d"), num);
+	}
+
 	int k = Str1.GetLength();
 	int j = (k - 1) / 3;	//閫楀彿涓暟
 	int l = k - j * 3; //璧峰浣嶇疆
@@ -500,7 +598,29 @@
 
 	return Str1;
 }
+CString fixToString(int num, int digit, int fracdigit)
+{
+	static CString Str1;
+	if (digit != 0) {
+		CString str2;
+		str2.Format(_T("%%%dd"), digit);
+		Str1.Format(str2, num);
 
+	}
+	else {
+		Str1.Format(_T("%d"), num);
+	}
+
+	int k = Str1.GetLength();
+	int j = (k - 1 - fracdigit) / 3;	//閫楀彿涓暟
+	int l = k - fracdigit - j * 3; //璧峰浣嶇疆
+	for (int i = l; i < k -fracdigit + j; i += 4)
+	{
+		Str1.Insert(i, _T(","));
+	}
+	if (fracdigit>0) Str1.Insert(k - fracdigit + j, '.');
+	return Str1;
+}
 CString & intToBinString(int num, int digits)
 {
 	static CString Str1;
@@ -514,5 +634,4 @@
 		mask >>= 1;
 	}
 	return Str1;
-}
-
+}
\ No newline at end of file

--
Gitblit v1.9.1