Jelajahi Sumber

1、禁用Panel面板自身弹出菜单;
2、新增删除指定设备名称的功能。

scbc.sat2 5 tahun lalu
induk
melakukan
38787bfe93

+ 7 - 0
SATHelper/SATHelper/DevicesWnd.cpp

@@ -61,6 +61,7 @@ BEGIN_MESSAGE_MAP(CDevicesWnd, CDockablePane)
 	ON_WM_SETTINGCHANGE()
 	ON_WM_PAINT()
 	
+	ON_WM_CONTEXTMENU()
 END_MESSAGE_MAP()
 
 /////////////////////////////////////////////////////////////////////////////
@@ -199,3 +200,9 @@ void CDevicesWnd::OnPaint()
 	brush.CreateSolidBrush(0xFFEFD5);
 	dc.FillRect(&rc, &brush);
 }
+
+
+void CDevicesWnd::OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/)
+{
+	// TODO: 在此处添加消息处理程序代码
+}

+ 2 - 0
SATHelper/SATHelper/DevicesWnd.h

@@ -73,5 +73,7 @@ protected:
 
 public:
 	afx_msg void OnPaint();
+	// 重载(禁用面板自带菜单)
+	afx_msg void OnContextMenu(CWnd* /*pWnd*/, CPoint /*point*/);
 };
 

+ 53 - 0
SATHelper/SATHelper/DlgService.cpp

@@ -38,6 +38,8 @@ BEGIN_MESSAGE_MAP(CDlgService, CDialogEx)
 	ON_BN_CLICKED(BTN_MODIFY_RUNNER_NAME, &CDlgService::OnBnClickedModifyRunnerName)
 	ON_BN_CLICKED(BTN_ADD_ANDROID, &CDlgService::OnBnClickedAddAndroid)
 	ON_WM_TIMER()
+	ON_NOTIFY(NM_RCLICK, IDC_LIST_DEVICES, &CDlgService::OnNMRClickListDevices)
+	ON_COMMAND(ID_DEVICES_DEL, &CDlgService::OnDevicesDel)
 END_MESSAGE_MAP()
 
 
@@ -306,3 +308,54 @@ void CDlgService::OnCancel()
 
 	//CDialogEx::OnCancel();
 }
+
+
+void CDlgService::OnNMRClickListDevices(NMHDR* pNMHDR, LRESULT* pResult)
+{
+	LPNMITEMACTIVATE pNMItemActivate = reinterpret_cast<LPNMITEMACTIVATE>(pNMHDR);
+	// TODO: 在此添加控件通知处理程序代码
+	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
+	if (pNMListView->iItem != -1)
+	{
+		CString strType = m_listDevices.GetItemText(pNMListView->iItem, 1);
+		// 过滤掉虚拟设备;
+		if (!strType.CompareNoCase(_T("虚拟")))
+			return;
+		
+		DWORD dwPos = GetMessagePos();
+		CPoint point(LOWORD(dwPos), HIWORD(dwPos));
+		CMenu menu;
+		//添加线程操作
+		if (!menu.LoadMenu(IDR_POPUP_DEVICES))			//这里是我们在1中定义的MENU的文件名称
+			return;
+		CMenu* popup = menu.GetSubMenu(0);
+		ASSERT(popup != NULL);
+		popup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, this);
+	}
+
+	*pResult = 0;
+}
+
+
+void CDlgService::OnDevicesDel()
+{
+	// TODO: 在此添加命令处理程序代码
+	// 获取选中的设备;
+	POSITION pos = m_listDevices.GetFirstSelectedItemPosition();
+	if (pos != NULL)
+	{
+		int nSelCur = m_listDevices.GetNextSelectedItem(pos);
+		if (nSelCur != -1)
+		{
+			CString strDeviceType = m_listDevices.GetItemText(nSelCur, 1);
+			CString strDeviceName = m_listDevices.GetItemText(nSelCur, 2);
+			if (!strDeviceName.IsEmpty() && strDeviceType.CompareNoCase(_T("虚拟")))
+			{
+				MessageBox(_T("即将删除设备:") + strDeviceName, _T("温馨提示!"), MB_ICONWARNING);
+				CSATClient::GetInstance()->TCPDelDevice(strDeviceName.GetString());
+				// 同时删除该项;
+				m_listDevices.DeleteItem(nSelCur);
+			}
+		}
+	}
+}

+ 2 - 0
SATHelper/SATHelper/DlgService.h

@@ -38,4 +38,6 @@ public:
 	afx_msg void OnTimer(UINT_PTR nIDEvent);
 	virtual void OnOK();
 	virtual void OnCancel();
+	afx_msg void OnNMRClickListDevices(NMHDR* pNMHDR, LRESULT* pResult);
+	afx_msg void OnDevicesDel();
 };

+ 4 - 2
SATHelper/SATHelper/Resource.h

@@ -118,6 +118,7 @@
 #define IDD_DLG_PROBAR                  319
 #define GIF_PROBAR                      322
 #define IDD_DLG_SERVICE                 323
+#define IDR_POPUP_DEVICES               326
 #define IDC_COMBO1                      1000
 #define IDC_COMBO2                      1001
 #define IDC_CHECK1                      1002
@@ -182,13 +183,14 @@
 #define ID_TRAYMENU_LOGIN               32825
 #define ID_BUTTON2                      32827
 #define ID_CHECK_LINEIN                 32828
+#define ID_DEVICES_DEL                32829
 
 // Next default values for new objects
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        326
-#define _APS_NEXT_COMMAND_VALUE         32829
+#define _APS_NEXT_RESOURCE_VALUE        327
+#define _APS_NEXT_COMMAND_VALUE         32830
 #define _APS_NEXT_CONTROL_VALUE         1015
 #define _APS_NEXT_SYMED_VALUE           310
 #endif

+ 1 - 1
SATHelper/SATHelper/SATClient.cpp

@@ -413,7 +413,7 @@ bool CSATClient::TCPAddDevice(std::string strDevice, bool bDel, BOOL bShowGif)
 
 bool CSATClient::TCPDelDevice(std::string strDevice, BOOL bShowGif)
 {
-	return TCPAddDevice(strDevice, false, bShowGif);
+	return TCPAddDevice(strDevice, true, bShowGif);
 }
 
 bool CSATClient::TCPQueryDevices(BOOL bShowGif)

+ 8 - 0
SATHelper/SATHelper/SATHelper.rc

@@ -401,6 +401,14 @@ BEGIN
     MENUITEM "Windows 7(&D)",               ID_VIEW_APPLOOK_WINDOWS_7
 END
 
+IDR_POPUP_DEVICES MENU
+BEGIN
+    POPUP "Devices"
+    BEGIN
+        MENUITEM "删除该设备",                       ID_DEVICES_DEL
+    END
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //

+ 4 - 2
SATHelper/SATHelper/resource.h

@@ -118,6 +118,7 @@
 #define IDD_DLG_PROBAR                  319
 #define GIF_PROBAR                      322
 #define IDD_DLG_SERVICE                 323
+#define IDR_POPUP_DEVICES               326
 #define IDC_COMBO1                      1000
 #define IDC_COMBO2                      1001
 #define IDC_CHECK1                      1002
@@ -182,13 +183,14 @@
 #define ID_TRAYMENU_LOGIN               32825
 #define ID_BUTTON2                      32827
 #define ID_CHECK_LINEIN                 32828
+#define ID_DEVICES_DEL                32829
 
 // Next default values for new objects
 // 
 #ifdef APSTUDIO_INVOKED
 #ifndef APSTUDIO_READONLY_SYMBOLS
-#define _APS_NEXT_RESOURCE_VALUE        326
-#define _APS_NEXT_COMMAND_VALUE         32829
+#define _APS_NEXT_RESOURCE_VALUE        327
+#define _APS_NEXT_COMMAND_VALUE         32830
 #define _APS_NEXT_CONTROL_VALUE         1015
 #define _APS_NEXT_SYMED_VALUE           310
 #endif