From 9b2d1e962bf802f75c44c1f5372fc4cf029e3f4e Mon Sep 17 00:00:00 2001
From: darker <mr.darker@163.com>
Date: 星期二, 11 二月 2025 11:11:13 +0800
Subject: [PATCH] 1. 添加SECS运行设置管理类

---
 SourceCode/Bond/Servo/Servo.cpp |   77 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/SourceCode/Bond/Servo/Servo.cpp b/SourceCode/Bond/Servo/Servo.cpp
index 81b50bc..d23cb02 100644
--- a/SourceCode/Bond/Servo/Servo.cpp
+++ b/SourceCode/Bond/Servo/Servo.cpp
@@ -6,6 +6,12 @@
 #include "Servo.h"
 #include "ServoDlg.h"
 #include "ServoGraph.h"
+#include "AlarmManager.h"
+#include "SECSConfigManager.h"
+
+// 声明全局变量,用于管理 GDI+ 初始化
+ULONG_PTR g_diplusToken;
+GdiplusStartupInput g_diplusStartupInput;
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -81,10 +87,50 @@
 	_tsplitpath_s(sAppFilename, sDrive, sDir, sFilename, sExt);
 	m_strAppDir = CString(sDrive) + CString(sDir);
 	m_strAppFile = CString(sFilename);
+	m_model.setWorkDir((LPTSTR)(LPCTSTR)m_strAppDir);
 
 
 	// 注册控件
 	CServoGraph::RegisterWndClass();
+
+
+	// 初始化Rx库
+	RX_Init();
+	HSMS_Initialize();
+
+
+	// 初始化 GDI+
+	InitGDIPlus();
+
+
+	// 初始化报警管理器
+	try {
+		if (!AlarmManager::getInstance().initAlarmTable()) {
+			AfxMessageBox("初始化报警管理器失败!");
+			return FALSE;
+		}
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("初始化报警管理器失败:%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+		return FALSE;
+	}
+
+
+	// 初始化SECS设置管理库
+	try {
+		if (!SECSConfigManager::getInstance().initSECSSetting()) {
+			AfxMessageBox("初始化SECS设置管理库失败!");
+			return FALSE;
+		}
+	}
+	catch (const std::exception& ex) {
+		CString errorMsg;
+		errorMsg.Format(_T("初始化SECS设置管理库失败:%s"), CString(ex.what()));
+		AfxMessageBox(errorMsg, MB_ICONERROR);
+		return FALSE;
+	}
 
 
 	CServoDlg dlg;
@@ -117,3 +163,34 @@
 	return FALSE;
 }
 
+int CServoApp::ExitInstance()
+{
+	m_model.term();
+	HSMS_Term();
+	RX_Term();
+
+	// 清理 GDI+
+	TermGDIPlus();
+
+	// 销毁报警表
+	AlarmManager::getInstance().termAlarmTable();
+
+	// 销毁SECS设置管理库
+	SECSConfigManager::getInstance().termSECSSetting();
+
+	return CWinApp::ExitInstance();
+}
+
+// 初始化 GDI+
+void CServoApp::InitGDIPlus()
+{
+	// 初始化 GDI+ 图形库
+	GdiplusStartup(&g_diplusToken, &g_diplusStartupInput, NULL);
+}
+
+// 清理 GDI+
+void CServoApp::TermGDIPlus()
+{
+	// 清理 GDI+ 图形库
+	GdiplusShutdown(g_diplusToken);
+}
\ No newline at end of file

--
Gitblit v1.9.3