IRControlWnd.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. // 这段 MFC 示例源代码演示如何使用 MFC Microsoft Office Fluent 用户界面
  2. // (“Fluent UI”)。该示例仅供参考,
  3. // 用以补充《Microsoft 基础类参考》和
  4. // MFC C++ 库软件随附的相关电子文档。
  5. // 复制、使用或分发 Fluent UI 的许可条款是单独提供的。
  6. // 若要了解有关 Fluent UI 许可计划的详细信息,请访问
  7. // https://go.microsoft.com/fwlink/?LinkId=238214.
  8. //
  9. // 版权所有(C) Microsoft Corporation
  10. // 保留所有权利。
  11. #include "stdafx.h"
  12. #include "framework.h"
  13. #include "IRControlWnd.h"
  14. #include "Resource.h"
  15. #include "MainFrm.h"
  16. #include "SATHelper.h"
  17. #include <filehelper.h>
  18. #ifdef _DEBUG
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #define new DEBUG_NEW
  22. #endif
  23. extern CMainFrame* g_pMainFrame;
  24. /////////////////////////////////////////////////////////////////////////////
  25. // CResourceViewBar
  26. unsigned char TwoHexChar2Char(char ch1, char ch2)
  27. {
  28. char Numb1;
  29. char Numb2;
  30. if (ch1 >= 'A')
  31. Numb1 = (toupper(ch1) - '0' - 7) * 16;
  32. else
  33. Numb1 = (ch1 - '0') * 16;
  34. if (ch2 >= 'A')
  35. Numb2 = (toupper(ch2) - '0' - 7);
  36. else
  37. Numb2 = (ch2 - '0');
  38. return (Numb1 + Numb2);
  39. }
  40. COLORREF HexColor2RGB(std::string strHexColor)
  41. {
  42. DWORD r = TwoHexChar2Char(strHexColor[0], strHexColor[1]);
  43. DWORD g = TwoHexChar2Char(strHexColor[2], strHexColor[3]);
  44. DWORD b = TwoHexChar2Char(strHexColor[4], strHexColor[5]);
  45. return RGB(r, g, b);
  46. }
  47. CIRControlWnd::CIRControlWnd() noexcept
  48. {
  49. m_nComboHeight = 0;
  50. m_bSendKey = FALSE;
  51. }
  52. CIRControlWnd::~CIRControlWnd()
  53. {
  54. FreeLogLibarary();
  55. for (std::vector<BtnInfo>::iterator it = m_vtBtnInfo.begin(); it != m_vtBtnInfo.end(); it++)
  56. {
  57. if (it->pBTN)
  58. //it->pBTN->DestroyWindow();
  59. delete it->pBTN;
  60. it->pBTN = NULL;
  61. }
  62. m_vtBtnInfo.clear();
  63. }
  64. // 重启进程按钮id;
  65. #define ID_BUTTON_RESTART_PROC 1
  66. // 复制框控件id;
  67. #define ID_CHECKBOX_SIGNAL_TYPE 2
  68. // 下拉框控件id;
  69. #define ID_COMBOBOX_SIGNAL_FILE 3
  70. BEGIN_MESSAGE_MAP(CIRControlWnd, CDockablePane)
  71. ON_WM_CREATE()
  72. ON_WM_SIZE()
  73. ON_COMMAND(ID_EXPAND_ALL, OnExpandAllProperties)
  74. ON_UPDATE_COMMAND_UI(ID_EXPAND_ALL, OnUpdateExpandAllProperties)
  75. ON_COMMAND(ID_SORTPROPERTIES, OnSortProperties)
  76. ON_UPDATE_COMMAND_UI(ID_SORTPROPERTIES, OnUpdateSortProperties)
  77. ON_COMMAND(ID_PROPERTIES1, OnProperties1)
  78. ON_UPDATE_COMMAND_UI(ID_PROPERTIES1, OnUpdateProperties1)
  79. ON_COMMAND(ID_PROPERTIES2, OnProperties2)
  80. ON_UPDATE_COMMAND_UI(ID_PROPERTIES2, OnUpdateProperties2)
  81. ON_WM_SETFOCUS()
  82. ON_WM_SETTINGCHANGE()
  83. ON_WM_PAINT()
  84. ON_MESSAGE(WM_IR_SHOT_IMG, OnIRShotImg)
  85. // 信号按钮;
  86. ON_COMMAND_RANGE(BTNID, BTNID + 100, OnSignalBtnClick)
  87. ON_UPDATE_COMMAND_UI_RANGE(BTNID, BTNID + 100, OnUpdateSignalBtn)
  88. // checkbox
  89. ON_UPDATE_COMMAND_UI(ID_CHECKBOX_SIGNAL_TYPE, OnUpdateCheckBox)
  90. ON_COMMAND(ID_CHECKBOX_SIGNAL_TYPE, OnCheckBoxClicked)
  91. //
  92. ON_CBN_SELCHANGE(ID_COMBOBOX_SIGNAL_FILE, &CIRControlWnd::OnCbnSelchangeSignal)
  93. ON_UPDATE_COMMAND_UI(ID_BUTTON_RESTART_PROC, OnUpdateBtnRestartProc)
  94. ON_COMMAND(ID_BUTTON_RESTART_PROC, OnBtnRestartProcClicked)
  95. END_MESSAGE_MAP()
  96. /////////////////////////////////////////////////////////////////////////////
  97. // CResourceViewBar 消息处理程序
  98. void CIRControlWnd::AdjustLayout()
  99. {
  100. if (GetSafeHwnd() == nullptr || (AfxGetMainWnd() != nullptr && AfxGetMainWnd()->IsIconic()))
  101. {
  102. return;
  103. }
  104. CRect rectClient;
  105. GetClientRect(rectClient);
  106. m_btnRestart.SetWindowPos(nullptr, rectClient.left + 5, rectClient.top + 5, 120, m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
  107. m_wndSignalCheck.SetWindowPos(nullptr, rectClient.left + 130, rectClient.top + 5, 120, m_nComboHeight, SWP_NOACTIVATE | SWP_NOZORDER);
  108. m_wndSignalCombo.SetWindowPos(nullptr, rectClient.left + 5, rectClient.top + m_nComboHeight + 10, 245, m_nComboHeight + 210, SWP_NOACTIVATE | SWP_NOZORDER);
  109. #if __PANE_DLG__
  110. m_dlgIRControl.SetWindowPos(nullptr, rectClient.left, rectClient.top + m_nComboHeight + 50, rectClient.Width(), rectClient.Height(), SWP_NOACTIVATE);
  111. #endif
  112. }
  113. int CIRControlWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
  114. {
  115. if (CDockablePane::OnCreate(lpCreateStruct) == -1)
  116. return -1;
  117. CRect rectDummy;
  118. rectDummy.SetRectEmpty();
  119. // 创建组合:
  120. const DWORD dwViewStyle = WS_CHILD | WS_VISIBLE | CBS_DROPDOWNLIST | WS_BORDER | CBS_SORT | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  121. if (!m_btnRestart.Create(_T("重启遥控器服务进程"), WS_CHILD | WS_VISIBLE, rectDummy, this, ID_BUTTON_RESTART_PROC))
  122. {
  123. TRACE0("未能创建遥控器组合 \n");
  124. return -1; // 未能创建
  125. }
  126. if (!m_wndSignalCheck.Create(_T("通用遥控器选择"), WS_CHILD | WS_VISIBLE | BS_AUTOCHECKBOX, rectDummy, this, ID_CHECKBOX_SIGNAL_TYPE))
  127. {
  128. TRACE0("未能创建信号集下拉框 \n");
  129. return -1; // 未能创建
  130. }
  131. m_wndSignalCheck.SetCheck(Global::g_Config.bGenerics ? BST_CHECKED : BST_UNCHECKED);
  132. m_wndSignalCheck.m_bHighlightChecked = TRUE;
  133. // CMFCButton只能用图标来显示check;
  134. m_wndSignalCheck.SetImage(IDB_UNCHECKED);
  135. m_wndSignalCheck.SetCheckedImage(IDB_CHECKED);
  136. m_wndSignalCheck.m_bTransparent = FALSE;
  137. m_wndSignalCheck.m_bDrawFocus = FALSE;
  138. m_wndSignalCheck.m_nFlatStyle = CMFCButton::BUTTONSTYLE_FLAT;
  139. m_wndSignalCheck.SizeToContent();
  140. if (!m_wndSignalCombo.Create(dwViewStyle| WS_VSCROLL| WS_HSCROLL, rectDummy, this, ID_COMBOBOX_SIGNAL_FILE))
  141. {
  142. TRACE0("未能创建信号集下拉框 \n");
  143. return -1; // 未能创建
  144. }
  145. LoadSignals();
  146. CRect rectCombo;
  147. m_wndSignalCombo.GetClientRect(&rectCombo);
  148. m_nComboHeight = rectCombo.Height();
  149. #if __PANE_DLG__
  150. if (!m_dlgIRControl.Create(IDD_DLG_IRCONTROL, this))
  151. {
  152. TRACE0("未能创建遥控器主窗口 \n");
  153. return -1; // 未能创建
  154. }
  155. m_dlgIRControl.ShowWindow(SW_SHOW);
  156. #else
  157. Loadlayout(m_vtBtnInfo);
  158. #endif
  159. // 设置最小窗体;
  160. SetMinSize((530, 300));
  161. // 校正布局;
  162. AdjustLayout();
  163. //////////////////////////////////////////////////////////////////////////
  164. // 启动红老鼠;
  165. if (!LoadLogLibarary())
  166. {
  167. AfxMessageBox("加载遥控dll失败,请检测dll是否正常!");
  168. }
  169. StartIRDevice(FALSE);
  170. std::thread t([](CIRControlWnd *pWnd) {
  171. //while (true)
  172. while( IsWindow(pWnd->m_hWnd) )
  173. {
  174. if (g_pMainFrame->m_bShotIR && pWnd->m_bSendKey)
  175. {
  176. pWnd->m_bSendKey = FALSE;
  177. Sleep(200);
  178. CUB530View* pView = (CUB530View*)g_pMainFrame->m_pUB530View->GetActiveView();
  179. if (pView)
  180. {
  181. pView->OnCutJpg();
  182. }
  183. }
  184. Sleep(20);
  185. }
  186. },this);
  187. t.detach();
  188. return 0;
  189. }
  190. void CIRControlWnd::OnSize(UINT nType, int cx, int cy)
  191. {
  192. CDockablePane::OnSize(nType, cx, cy);
  193. TRACE2("坐标:%d,%d\n", cx, cy);
  194. AdjustLayout();
  195. }
  196. void CIRControlWnd::OnExpandAllProperties()
  197. {
  198. //m_wndPropList.ExpandAll();
  199. }
  200. void CIRControlWnd::OnUpdateExpandAllProperties(CCmdUI* /* pCmdUI */)
  201. {
  202. }
  203. void CIRControlWnd::OnSortProperties()
  204. {
  205. //m_wndPropList.SetAlphabeticMode(!m_wndPropList.IsAlphabeticMode());
  206. }
  207. void CIRControlWnd::OnUpdateSortProperties(CCmdUI* pCmdUI)
  208. {
  209. //pCmdUI->SetCheck(m_wndPropList.IsAlphabeticMode());
  210. }
  211. void CIRControlWnd::OnProperties1()
  212. {
  213. // TODO: 在此处添加命令处理程序代码
  214. }
  215. void CIRControlWnd::OnUpdateProperties1(CCmdUI* /*pCmdUI*/)
  216. {
  217. // TODO: 在此处添加命令更新 UI 处理程序代码
  218. }
  219. void CIRControlWnd::OnProperties2()
  220. {
  221. // TODO: 在此处添加命令处理程序代码
  222. }
  223. void CIRControlWnd::OnUpdateProperties2(CCmdUI* /*pCmdUI*/)
  224. {
  225. // TODO: 在此处添加命令更新 UI 处理程序代码
  226. }
  227. void CIRControlWnd::OnSetFocus(CWnd* pOldWnd)
  228. {
  229. CDockablePane::OnSetFocus(pOldWnd);
  230. }
  231. void CIRControlWnd::OnSettingChange(UINT uFlags, LPCTSTR lpszSection)
  232. {
  233. CDockablePane::OnSettingChange(uFlags, lpszSection);
  234. //SetPropListFont();
  235. }
  236. void CIRControlWnd::OnCbnSelchangeSignal()
  237. {
  238. CString strSignal;
  239. int nCurSel = m_wndSignalCombo.GetCurSel();
  240. if ( nCurSel != CB_ERR )
  241. {
  242. std::string signalpath;
  243. m_wndSignalCombo.GetLBText(nCurSel, strSignal);
  244. // 保存到配置文件中;
  245. Global::g_Config.use_signal = strSignal.GetString();
  246. WritePrivateProfileString("ir-device", "use-signal", strSignal.GetString(), Global::g_szConfig);
  247. }
  248. DisableSignalBtn();
  249. ReLoadSignalXml();
  250. }
  251. void CIRControlWnd::SetPropListFont()
  252. {
  253. ::DeleteObject(m_fntPropList.Detach());
  254. LOGFONT lf;
  255. afxGlobalData.fontRegular.GetLogFont(&lf);
  256. NONCLIENTMETRICS info;
  257. info.cbSize = sizeof(info);
  258. afxGlobalData.GetNonClientMetrics(info);
  259. lf.lfHeight = info.lfMenuFont.lfHeight;
  260. lf.lfWeight = info.lfMenuFont.lfWeight;
  261. lf.lfItalic = info.lfMenuFont.lfItalic;
  262. m_fntPropList.CreateFontIndirect(&lf);
  263. //m_wndObjectCombo.SetFont(&m_fntPropList);
  264. }
  265. void CIRControlWnd::StartIRDevice(BOOL bReStart)
  266. {
  267. std::thread t([&](BOOL _bReStart_) {
  268. // 结束进程;
  269. if (_bReStart_ && g_CloseApp)
  270. g_CloseApp();
  271. // 默认加载配置的信号集文件;
  272. std::string signale = Global::g_Config.bGenerics ? Global::g_Config.signaldir + "\\general\\" : Global::g_Config.signaldir + "\\product\\";
  273. signale.append(Global::g_Config.use_signal + ".xml");
  274. if (!PathFileExists(signale.c_str()))
  275. {
  276. m_wndSignalCombo.SetCurSel(-1);
  277. signale = ".\\default.xml";
  278. }
  279. else
  280. {
  281. m_wndSignalCombo.SelectString(0, Global::g_Config.use_signal.c_str());
  282. }
  283. if ( !g_IsAppRunning(Global::g_Config.redratpath.c_str()) )
  284. {
  285. if (g_StartIRApp(Global::g_Config.redratpath.c_str(), signale.c_str(), 40000))
  286. {
  287. TRACE("启动红老鼠进程启动成功\r");
  288. }
  289. else
  290. {
  291. TRACE("启动红老鼠进程启动失败\r");
  292. AfxMessageBox("启动红老鼠进程启动失败!");
  293. return 0;
  294. }
  295. }
  296. BOOL bRet = FALSE;
  297. // 连接服务器;
  298. for (int i = 0; i < 5; i++)
  299. {
  300. if ((bRet = g_Connect(_T("127.0.0.1"), 40000)))
  301. break;
  302. Sleep(1000);
  303. }
  304. if (!bRet)
  305. AfxMessageBox("连接红老鼠服务端失败,请重启设备!");
  306. // 更新按钮状态;
  307. UpdateSignalBtnStatus();
  308. // 获取设备列表,以逗号分隔;
  309. std::string devices = g_getDeviceNames();
  310. if (devices.size() == 0)
  311. {
  312. AfxMessageBox("当前无红老鼠设备连接!");
  313. }
  314. return 1;
  315. }, bReStart);
  316. t.detach();
  317. }
  318. void CIRControlWnd::ReLoadSignalXml()
  319. {
  320. std::string signaldir,signalpath;
  321. if (Global::g_Config.bGenerics)
  322. {
  323. signaldir = Global::g_Config.signaldir + "\\general\\";
  324. }
  325. else
  326. {
  327. signaldir = Global::g_Config.signaldir + "\\product\\";
  328. }
  329. signalpath = signaldir;
  330. signalpath.append(Global::g_Config.use_signal + ".xml");
  331. if (!PathFileExists(signalpath.c_str()))
  332. {
  333. AfxMessageBox(_T("该信号文件不存在!"));
  334. // 设置默认的;
  335. CString strSignal;
  336. m_wndSignalCombo.SetCurSel(0);
  337. m_wndSignalCombo.GetLBText(0, strSignal);
  338. signalpath = signaldir;
  339. signalpath.append(strSignal.GetString());
  340. signalpath.append(".xml");
  341. // 保存到配置文件中;
  342. Global::g_Config.use_signal = strSignal.GetString();
  343. WritePrivateProfileString("ir-device", "use-signal", strSignal.GetString(), Global::g_szConfig);
  344. }
  345. else // 切换通用类型时用到;
  346. {
  347. m_wndSignalCombo.SelectString(0, Global::g_Config.use_signal.c_str());
  348. }
  349. // 加载指定目录的xml信号集文件;
  350. if (!g_loadSignalDataSet(signalpath.c_str()))
  351. {
  352. TRACE("加载信号集文件失败\r");
  353. }
  354. else
  355. {
  356. TRACE("加载信号集文件成功\r");
  357. UpdateSignalBtnStatus();
  358. }
  359. }
  360. void CIRControlWnd::LoadSignals()
  361. {
  362. filehelper fh;
  363. fh.getfiles_findout_subfolder((Global::g_Config.signaldir + "\\general\\").c_str(), NULL, &m_vtsignal_gen);
  364. fh.getfiles_findout_subfolder((Global::g_Config.signaldir + "\\product\\").c_str(), NULL, &m_vtsignal_pro);
  365. // 添加到combobox中;
  366. if (Global::g_Config.bGenerics )
  367. {
  368. m_wndSignalCombo.ResetContent();
  369. for ( auto it : m_vtsignal_gen)
  370. {
  371. m_wndSignalCombo.AddString(fh.getfilename(it).c_str());
  372. }
  373. }
  374. else
  375. {
  376. m_wndSignalCombo.ResetContent();
  377. for (auto it : m_vtsignal_pro)
  378. {
  379. m_wndSignalCombo.AddString(fh.getfilename(it).c_str());
  380. }
  381. }
  382. AutoSetDroppedWidth();
  383. }
  384. void CIRControlWnd::Loadlayout(std::vector<BtnInfo>& vt)
  385. {
  386. // 解析xml;
  387. std::string path;
  388. path.append(Global::g_szCurModuleDir);
  389. path.append("layout.xml");
  390. tinyxml2::XMLDocument doc;
  391. if (tinyxml2::XML_SUCCESS != doc.LoadFile(path.c_str()))
  392. {
  393. return;
  394. }
  395. vt.clear();
  396. std::string data;
  397. tinyxml2::XMLElement* pXmlRoot = NULL;
  398. if ((pXmlRoot = doc.RootElement()) != NULL)
  399. {
  400. if (_tcsicmp(pXmlRoot->Value(), "ButtonList") == 0)
  401. {
  402. // 子项;
  403. tinyxml2::XMLElement* pXmlElent = pXmlRoot->FirstChildElement();
  404. while (pXmlElent)
  405. {
  406. BtnInfo btninfo;
  407. if (_tcsicmp(pXmlElent->Value(), _T("ITEM")) == 0)
  408. {
  409. tinyxml2::XMLElement* pItem = pXmlElent->FirstChildElement();
  410. while (pItem)
  411. {
  412. if (_tcsicmp(pItem->Value(), _T("NAME")) == 0)
  413. {
  414. btninfo.name = pItem->GetText();
  415. }
  416. else if (_tcsicmp(pItem->Value(), _T("WIDTH")) == 0)
  417. {
  418. data = pItem->GetText();
  419. btninfo.width = _ttol(data.c_str());
  420. }
  421. else if (_tcsicmp(pItem->Value(), _T("HEIGHT")) == 0)
  422. {
  423. data = pItem->GetText();
  424. btninfo.height = _ttol(data.c_str());
  425. }
  426. else if (_tcsicmp(pItem->Value(), _T("COLOR")) == 0)
  427. {
  428. data = pItem->GetText();
  429. btninfo.color = HexColor2RGB(data);
  430. }
  431. btninfo.pBTN = new CMFCButton();
  432. pItem = pItem->NextSiblingElement();
  433. }
  434. }
  435. vt.push_back(btninfo);
  436. pXmlElent = pXmlElent->NextSiblingElement();
  437. }
  438. }
  439. }
  440. int sx = 0, sy = m_nComboHeight*2+15;
  441. int i = 0, id = 10000;
  442. DWORD dwStyle = WS_CHILD | WS_VISIBLE;
  443. for (std::vector<BtnInfo>::iterator it = vt.begin(); it != vt.end(); it++)
  444. {
  445. if (i != 0 && i % 4 == 0)
  446. {//换行;
  447. sy += it->height + 5;
  448. }
  449. sx = (i % 4) * it->width + (i % 4 + 1) * 5;
  450. it->pBTN->Create(it->name.c_str(), dwStyle, CRect(sx, sy, sx + it->width, sy + it->height), this, BTNID + i);
  451. // 设置透明false以显示背景色
  452. it->pBTN->m_bTransparent = FALSE;
  453. it->pBTN->m_bDontUseWinXPTheme = TRUE;
  454. // 设置背景色;
  455. it->pBTN->SetFaceColor(it->color, TRUE);
  456. // 消除单击时黑色内圈;
  457. it->pBTN->m_bDrawFocus = FALSE;
  458. // 设置按钮扁平样式;
  459. it->pBTN->m_nFlatStyle = CMFCButton::FlatStyle::BUTTONSTYLE_FLAT;
  460. // 设置鼠标形状;
  461. it->pBTN->SetMouseCursorHand();
  462. // 存入map中;
  463. m_map_btn.insert(std::pair<UINT, BtnInfo&>(BTNID+i, *it));
  464. i++;
  465. }
  466. }
  467. // 如果CDockablePane无控件,改变大小时背景会刷新失败;
  468. // 所以要重载onpaint;
  469. void CIRControlWnd::OnPaint()
  470. {
  471. CPaintDC dc(this); // device context for painting
  472. // TODO: 在此处添加消息处理程序代码
  473. // 不为绘图消息调用 CDockablePane::OnPaint();
  474. CRect rc;
  475. GetClientRect(rc);
  476. CBrush brush;
  477. brush.CreateSolidBrush(0xFFEFD5);
  478. dc.FillRect(&rc, &brush);
  479. }
  480. void CIRControlWnd::OnSignalBtnClick(UINT uId) // 发送遥控信号;
  481. {
  482. CWnd* pWnd = GetFocus();
  483. int id = pWnd->GetDlgCtrlID();
  484. if (id >= BTNID && id <= BTNID + 100)
  485. {
  486. CString text;
  487. pWnd->GetWindowText(text);
  488. // 发送单信号;
  489. if (g_sendSignal(text.GetString(), 1, 20))
  490. {
  491. m_bSendKey = TRUE;
  492. TRACE("发送单信号成功\n");
  493. }
  494. else
  495. {
  496. TRACE("发送单信号失败\n");
  497. }
  498. }
  499. }
  500. void CIRControlWnd::OnUpdateSignalBtn(CCmdUI* pCmdUI)
  501. {
  502. pCmdUI->Enable(m_map_btn.find(pCmdUI->m_nID)->second.bEnable);
  503. }
  504. void CIRControlWnd::OnUpdateCheckBox(CCmdUI* pCmdUI)
  505. {
  506. pCmdUI->Enable();
  507. }
  508. void CIRControlWnd::OnCheckBoxClicked()
  509. {
  510. Global::g_Config.bGenerics = m_wndSignalCheck.IsChecked();
  511. // 保存到配置文件中;
  512. WritePrivateProfileString("ir-device", "generics", Global::g_Config.bGenerics ? "1" : "0", Global::g_szConfig);
  513. // 添加到combobox中;
  514. if (Global::g_Config.bGenerics)
  515. {
  516. m_wndSignalCombo.ResetContent();
  517. for (auto it : m_vtsignal_gen)
  518. {
  519. m_wndSignalCombo.AddString(filehelper::getfilename(it).c_str());
  520. }
  521. }
  522. else
  523. {
  524. m_wndSignalCombo.ResetContent();
  525. for (auto it : m_vtsignal_pro)
  526. {
  527. m_wndSignalCombo.AddString(filehelper::getfilename(it).c_str());
  528. }
  529. }
  530. AutoSetDroppedWidth();
  531. DisableSignalBtn();
  532. ReLoadSignalXml();
  533. }
  534. void CIRControlWnd::OnUpdateBtnRestartProc(CCmdUI* pCmdUI)
  535. {
  536. pCmdUI->Enable(TRUE);
  537. }
  538. void CIRControlWnd::OnBtnRestartProcClicked() // 重启红老鼠;
  539. {
  540. DisableSignalBtn();
  541. StartIRDevice();
  542. }
  543. void CIRControlWnd::UpdateSignalBtnStatus()
  544. {
  545. // 获取信号集;
  546. if (g_getSignalsName )
  547. {
  548. // 获取信号数据集,以\n分隔;
  549. std::string data = g_getSignalsName();
  550. CString signals = data.append(1, '\n').c_str();
  551. signals.MakeUpper();
  552. for ( std::vector<BtnInfo>::iterator it = m_vtBtnInfo.begin(); it != m_vtBtnInfo.end(); it++)
  553. {
  554. if ( signals.Find((it->name+'\n').c_str()) == -1 )
  555. {
  556. it->bEnable = false;
  557. }
  558. else
  559. {
  560. it->bEnable = true;
  561. }
  562. }
  563. }
  564. }
  565. void CIRControlWnd::AutoSetDroppedWidth()
  566. {
  567. return AddHScroll();
  568. // Set the height of every item so the item
  569. // is completely visible.
  570. CString str;
  571. CSize sz;
  572. int dx = 0;
  573. CDC* pDC = m_wndSignalCombo.GetDC();
  574. for (int i = 0; i < m_wndSignalCombo.GetCount(); i++)
  575. {
  576. m_wndSignalCombo.GetLBText(i, str);
  577. sz = pDC->GetTextExtent(str);
  578. // Only want to set the item height if the current height
  579. // is not big enough.
  580. if (m_wndSignalCombo.GetItemHeight(i) < sz.cy)
  581. m_wndSignalCombo.SetItemHeight(i, sz.cy);
  582. // Only want to set the item width if the current width
  583. // is not big enough.
  584. if (m_wndSignalCombo.GetDroppedWidth() < sz.cx)
  585. {
  586. m_wndSignalCombo.SetDroppedWidth(sz.cx + 50);
  587. }
  588. }
  589. m_wndSignalCombo.ReleaseDC(pDC);
  590. }
  591. void CIRControlWnd::AddHScroll()
  592. {
  593. // Find the longest string in the combo box.
  594. CString str;
  595. CSize sz;
  596. int dx = 0;
  597. TEXTMETRIC tm = { 0 };
  598. CDC* pDC = m_wndSignalCombo.GetDC();
  599. CFont* pFont = m_wndSignalCombo.GetFont();
  600. // Select the listbox font, save the old font
  601. CFont* pOldFont = pDC->SelectObject(pFont);
  602. // Get the text metrics for avg char width
  603. pDC->GetTextMetrics(&tm);
  604. for (int i = 0; i < m_wndSignalCombo.GetCount(); i++)
  605. {
  606. m_wndSignalCombo.GetLBText(i, str);
  607. sz = pDC->GetTextExtent(str);
  608. // Add the avg width to prevent clipping
  609. sz.cx += tm.tmAveCharWidth;
  610. if (sz.cx > dx)
  611. dx = sz.cx;
  612. }
  613. // Select the old font back into the DC
  614. pDC->SelectObject(pOldFont);
  615. m_wndSignalCombo.ReleaseDC(pDC);
  616. // Set the horizontal extent so every character of all strings can
  617. // be scrolled to.
  618. m_wndSignalCombo.SetHorizontalExtent(dx);
  619. }
  620. LRESULT CIRControlWnd::OnIRShotImg(WPARAM wparam, LPARAM lparam)
  621. {
  622. return LRESULT();
  623. }