瀏覽代碼

细节修改;

Jeff 5 年之前
父節點
當前提交
8ef157c87a
共有 2 個文件被更改,包括 79 次插入13 次删除
  1. 74 13
      VideoCapture/VideoCapture/IRControlWnd.cpp
  2. 5 0
      VideoCapture/VideoCapture/IRControlWnd.h

+ 74 - 13
VideoCapture/VideoCapture/IRControlWnd.cpp

@@ -219,6 +219,7 @@ int CIRControlWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
 	if (!g_Connect(_T("127.0.0.1"), 40000))
 		AfxMessageBox("连接红老鼠服务端失败,请重启设备!");
 
+	UpdateSignalBtnStatus();
 	// 获取设备列表,以逗号分隔;
 	std::string devices = g_getDeviceNames();
 	if (devices.size() == 0)
@@ -330,6 +331,7 @@ void CIRControlWnd::OnCbnSelchangeSignal()
 		else
 		{
 			TRACE("加载信号集文件成功\r");
+			UpdateSignalBtnStatus();
 		}
 
 		// 保存到配置文件中;
@@ -390,7 +392,23 @@ void CIRControlWnd::LoadSignals()
 	signalpath.append(Global::g_Config.use_signal + ".xml");
 	if (!PathFileExists(signalpath.c_str()))
 	{
+		CString strSignal;
 		m_wndSignalCombo.SetCurSel(0);
+		m_wndSignalCombo.GetLBText(0, strSignal);
+
+		// 加载指定目录的xml信号集文件;
+		if (!g_loadSignalDataSet(signalpath.c_str()))
+		{
+			TRACE("加载信号集文件失败\r");
+		}
+		else
+		{
+			TRACE("加载信号集文件成功\r");
+			UpdateSignalBtnStatus();
+		}
+
+		// 保存到配置文件中;
+		WritePrivateProfileString("ir-device", "use-signal", strSignal.GetString(), Global::g_szConfig);
 	}
 	else
 	{
@@ -461,27 +479,31 @@ void CIRControlWnd::Loadlayout(std::vector<BtnInfo>& vt)
 	int sx = 0, sy = 80;
 	int i = 0, id = 10000;
 	DWORD dwStyle = WS_CHILD | WS_VISIBLE;
-	for (auto it : vt)
+	for (std::vector<BtnInfo>::iterator it = vt.begin(); it != vt.end(); it++)
 	{
 		if (i != 0 && i % 4 == 0)
 		{//换行;
-			sy += it.height + 5;
+			sy += it->height + 5;
 		}
 
-		sx = (i % 4) * it.width + (i % 4 + 1) * 5;
+		sx = (i % 4) * it->width + (i % 4 + 1) * 5;
 
-		it.pBTN->Create(it.name.c_str(), dwStyle, CRect(sx, sy, sx + it.width, sy + it.height), this, BTNID + i);
+		it->pBTN->Create(it->name.c_str(), dwStyle, CRect(sx, sy, sx + it->width, sy + it->height), this, BTNID + i);
 		// 设置透明false以显示背景色
-		it.pBTN->m_bTransparent = FALSE;
-		it.pBTN->m_bDontUseWinXPTheme = TRUE;
+		it->pBTN->m_bTransparent = FALSE;
+		it->pBTN->m_bDontUseWinXPTheme = TRUE;
 		// 设置背景色;
-		it.pBTN->SetFaceColor(it.color, TRUE);
+		it->pBTN->SetFaceColor(it->color, TRUE);
 		// 消除单击时黑色内圈;
-		it.pBTN->m_bDrawFocus = FALSE;
+		it->pBTN->m_bDrawFocus = FALSE;
 		// 设置按钮扁平样式;
-		it.pBTN->m_nFlatStyle = CMFCButton::FlatStyle::BUTTONSTYLE_FLAT;
+		it->pBTN->m_nFlatStyle = CMFCButton::FlatStyle::BUTTONSTYLE_FLAT;
 		// 设置鼠标形状;
-		it.pBTN->SetMouseCursorHand();
+		it->pBTN->SetMouseCursorHand();
+
+		// 存入map中;
+		m_map_btn.insert(std::pair<UINT, BtnInfo&>(BTNID+i, *it));
+
 		i++;
 	}
 }
@@ -510,9 +532,8 @@ void CIRControlWnd::OnSignalBtnClick(UINT uId)
 	{
 		CString text;
 		pWnd->GetWindowText(text);
-		//AfxMessageBox(text);
 		// 发送单信号;
-		if (g_sendSignal(text.GetString(), 1, 100))
+		if (g_sendSignal(text.GetString(), 1, 20))
 		{
 			TRACE("发送单信号成功\n");
 		}
@@ -525,7 +546,7 @@ void CIRControlWnd::OnSignalBtnClick(UINT uId)
 
 void CIRControlWnd::OnUpdateSignalBtn(CCmdUI* pCmdUI)
 {
-	pCmdUI->Enable();
+	pCmdUI->Enable(m_map_btn.find(pCmdUI->m_nID)->second.bEnable);
 }
 
 void CIRControlWnd::OnUpdateCheckBox(CCmdUI* pCmdUI)
@@ -561,7 +582,23 @@ void CIRControlWnd::OnCheckBoxClicked()
 	signalpath.append(Global::g_Config.use_signal + ".xml");
 	if (!PathFileExists(signalpath.c_str()))
 	{
+		CString strSignal;
 		m_wndSignalCombo.SetCurSel(0);
+		m_wndSignalCombo.GetLBText(0, strSignal);
+
+		// 加载指定目录的xml信号集文件;
+		if (!g_loadSignalDataSet(signalpath.c_str()))
+		{
+			TRACE("加载信号集文件失败\r");
+		}
+		else
+		{
+			TRACE("加载信号集文件成功\r");
+			UpdateSignalBtnStatus();
+		}
+
+		// 保存到配置文件中;
+		WritePrivateProfileString("ir-device", "use-signal", strSignal.GetString(), Global::g_szConfig);
 	}
 	else
 	{
@@ -619,5 +656,29 @@ void CIRControlWnd::OnBtnRestartProcClicked()
 	else
 	{
 		TRACE("加载信号集文件成功\r");
+		UpdateSignalBtnStatus();
+	}
+}
+
+void CIRControlWnd::UpdateSignalBtnStatus()
+{
+	// 获取信号集;
+	if (g_getSignalsName )
+	{
+		// 获取信号数据集,以\n分隔;
+		std::string data = g_getSignalsName();
+		CString signals = data.append(1, '\n').c_str();
+		signals.MakeUpper();
+		for ( std::vector<BtnInfo>::iterator it = m_vtBtnInfo.begin(); it != m_vtBtnInfo.end(); it++)
+		{
+			if ( signals.Find((it->name+'\n').c_str()) == -1 )
+			{
+				it->bEnable = false;
+			}
+			else
+			{
+				it->bEnable = true;
+			}
+		}
 	}
 }

+ 5 - 0
VideoCapture/VideoCapture/IRControlWnd.h

@@ -10,6 +10,7 @@
 // 保留所有权利。
 
 #include "DlgIRControl.h"
+#include <map>
 #pragma once
 
 // 按钮id起始值;
@@ -23,6 +24,7 @@ typedef struct __BTN_INFO__
 	int height;
 	DWORD color;
 	CMFCButton *pBTN;
+	bool bEnable = false;
 }BtnInfo, *pBtnInfo;
 
 class CIRControlToolBar : public CMFCToolBar
@@ -92,6 +94,7 @@ protected:
 
 	int m_nComboHeight;
 public:
+	std::map<UINT, BtnInfo&> m_map_btn;
 	std::vector<std::string> m_vtsignal_gen;
 	std::vector<std::string> m_vtsignal_pro;
 	void LoadSignals();
@@ -108,5 +111,7 @@ public:
 	// 更新重启按钮状态;
 	afx_msg void OnUpdateBtnRestartProc(CCmdUI* pCmdUI);
 	afx_msg void OnBtnRestartProcClicked();
+	// 更新按钮实际状态;
+	void UpdateSignalBtnStatus();
 };