From 4a487efb06d6c314fd46ba52a2ba921618c676dd Mon Sep 17 00:00:00 2001
From: mrDarker <mr.darker@163.com>
Date: 星期六, 13 九月 2025 17:15:37 +0800
Subject: [PATCH] 1. SG精度检在任务栏菜单添加打开程序运行目录功能
---
SourceCode/Bond/SGMeasurement/resource.h | 3 ++-
SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj | 1 +
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h | 1 +
SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters | 3 +++
SourceCode/Bond/SGMeasurement/SGMeasurement.rc | 0
SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp | 35 +++++++++++++++++++++++++++++------
SourceCode/Bond/SGMeasurement/res/menu_open_dir.ico | 0
7 files changed, 36 insertions(+), 7 deletions(-)
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurement.rc b/SourceCode/Bond/SGMeasurement/SGMeasurement.rc
index fd45e92..e2b5b50 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurement.rc
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurement.rc
Binary files differ
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj b/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj
index 33c1c14..f2b867e 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj
@@ -238,6 +238,7 @@
</ItemGroup>
<ItemGroup>
<Image Include="res\menu_close.ico" />
+ <Image Include="res\menu_open_dir.ico" />
<Image Include="res\menu_restore.ico" />
<Image Include="res\SGMeasurement.ico" />
</ItemGroup>
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters b/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters
index df340e5..9821b7b 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurement.vcxproj.filters
@@ -98,5 +98,8 @@
<Image Include="res\menu_close.ico">
<Filter>璧勬簮鏂囦欢</Filter>
</Image>
+ <Image Include="res\menu_open_dir.ico">
+ <Filter>璧勬簮鏂囦欢</Filter>
+ </Image>
</ItemGroup>
</Project>
\ No newline at end of file
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
index 6ee6018..c1c2459 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.cpp
@@ -17,6 +17,7 @@
#define DeviceID 0
// 鎵樼洏鍥炬爣 ID 涓庢秷鎭畯
+#define ID_TRAY_OPEN_DIR 2000 // 鎵撳紑鐩綍
#define ID_TRAY_RESTORE 2001 // 鎭㈠绐楀彛
#define ID_TRAY_EXIT 2002 // 閫�鍑虹▼搴�
#define WM_TRAY_ICON_NOTIFY (WM_USER + 1000) // 鎵樼洏鍥炬爣鍥炶皟娑堟伅 ID
@@ -947,6 +948,7 @@
ON_WM_DRAWITEM()
ON_WM_CLOSE()
ON_MESSAGE(WM_TRAY_ICON_NOTIFY, &CSGMeasurementDlg::OnTrayIconClick)
+ ON_COMMAND(ID_TRAY_OPEN_DIR, &CSGMeasurementDlg::OnTrayOpenDir)
ON_COMMAND(ID_TRAY_RESTORE, &CSGMeasurementDlg::OnTrayRestore)
ON_COMMAND(ID_TRAY_EXIT, &CSGMeasurementDlg::OnTrayExit)
ON_BN_CLICKED(IDC_BUTTON_CONNECT, &CSGMeasurementDlg::OnBnClickedButtonConnect)
@@ -1206,6 +1208,10 @@
// 鍥炬爣
HICON hIcon = nullptr;
+ if (id == ID_TRAY_OPEN_DIR) {
+ hIcon = AfxGetApp()->LoadIcon(IDI_ICON_OPEN_DIR);
+ }
+
if (id == ID_TRAY_RESTORE) {
hIcon = AfxGetApp()->LoadIcon(IDI_ICON_RESTORE);
}
@@ -1220,6 +1226,10 @@
// 鏂囨湰
CString str;
+ if (id == ID_TRAY_OPEN_DIR) {
+ str = _T("鎵撳紑鐩綍");
+ }
+
if (id == ID_TRAY_RESTORE) {
str = _T("鎭㈠鐣岄潰");
}
@@ -1263,22 +1273,23 @@
// 鍙抽敭鐐瑰嚮寮瑰嚭鑿滃崟
CMenu menu;
menu.CreatePopupMenu();
+ menu.AppendMenu(MF_OWNERDRAW, ID_TRAY_OPEN_DIR, (LPCTSTR)ID_TRAY_OPEN_DIR);
menu.AppendMenu(MF_OWNERDRAW, ID_TRAY_RESTORE, (LPCTSTR)ID_TRAY_RESTORE);
menu.AppendMenu(MF_OWNERDRAW, ID_TRAY_EXIT, (LPCTSTR)ID_TRAY_EXIT);
-
- // 鍔犺浇鍥炬爣
- HICON hIconRestore = (HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_RESTORE), IMAGE_ICON, 16, 16, LR_SHARED);
- HICON hIconExit = (HICON)::LoadImage(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_ICON_EXIT), IMAGE_ICON, 16, 16, LR_SHARED);
// 璁剧疆鍥炬爣鍒拌彍鍗曢」
MENUITEMINFO mii = { sizeof(MENUITEMINFO) };
mii.fMask = MIIM_BITMAP;
- // 鎭㈠鑿滃崟椤瑰浘鏍�
+ // 鎵撳紑鐩綍鑿滃崟椤瑰浘鏍�
+ mii.hbmpItem = HBMMENU_CALLBACK;
+ menu.SetMenuItemInfo(ID_TRAY_OPEN_DIR, &mii);
+
+ // 鎭㈠绐楀彛鑿滃崟椤瑰浘鏍�
mii.hbmpItem = HBMMENU_CALLBACK;
menu.SetMenuItemInfo(ID_TRAY_RESTORE, &mii);
- // 閫�鍑鸿彍鍗曢」鍥炬爣
+ // 閫�鍑虹▼搴忚彍鍗曢」鍥炬爣
mii.hbmpItem = HBMMENU_CALLBACK;
menu.SetMenuItemInfo(ID_TRAY_EXIT, &mii);
@@ -1292,6 +1303,18 @@
return 0;
}
+void CSGMeasurementDlg::OnTrayOpenDir()
+{
+ CString strDir = GetAppDirectory();
+ if (PathFileExists(strDir)) {
+ ShellExecute(NULL, _T("open"), strDir, NULL, NULL, SW_SHOWDEFAULT);
+ AppendLogLineRichStyled(_T("宸叉墦寮�绋嬪簭鐩綍"), LOG_COLOR_SUCCESS);
+ }
+ else {
+ AppendLogLineRichStyled(_T("鐩綍涓嶅瓨鍦紝鏃犳硶鎵撳紑"), LOG_COLOR_ERROR);
+ }
+}
+
void CSGMeasurementDlg::OnTrayRestore()
{
ShowWindow(SW_SHOW); // 鎭㈠绐楀彛
diff --git a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h
index 41d41e5..aa76701 100644
--- a/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h
+++ b/SourceCode/Bond/SGMeasurement/SGMeasurementDlg.h
@@ -41,6 +41,7 @@
afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
afx_msg void OnClose();
afx_msg LRESULT OnTrayIconClick(WPARAM wParam, LPARAM lParam);
+ afx_msg void OnTrayOpenDir();
afx_msg void OnTrayRestore();
afx_msg void OnTrayExit();
afx_msg void OnBnClickedButtonConnect();
diff --git a/SourceCode/Bond/SGMeasurement/res/menu_open_dir.ico b/SourceCode/Bond/SGMeasurement/res/menu_open_dir.ico
new file mode 100644
index 0000000..c3a1426
--- /dev/null
+++ b/SourceCode/Bond/SGMeasurement/res/menu_open_dir.ico
Binary files differ
diff --git a/SourceCode/Bond/SGMeasurement/resource.h b/SourceCode/Bond/SGMeasurement/resource.h
index 9286258..c338fc3 100644
--- a/SourceCode/Bond/SGMeasurement/resource.h
+++ b/SourceCode/Bond/SGMeasurement/resource.h
@@ -9,6 +9,7 @@
#define IDR_MAINFRAME 128
#define IDI_ICON_RESTORE 130
#define IDI_ICON_EXIT 131
+#define IDI_ICON_OPEN_DIR 132
#define IDC_IPADDRESS 1000
#define IDC_BUTTON_CONNECT 1001
#define IDC_BUTTON_DISCONNECT 1002
@@ -37,7 +38,7 @@
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE 132
+#define _APS_NEXT_RESOURCE_VALUE 133
#define _APS_NEXT_COMMAND_VALUE 32771
#define _APS_NEXT_CONTROL_VALUE 1023
#define _APS_NEXT_SYMED_VALUE 101
--
Gitblit v1.9.3