CSystemSettingWnd.cpp 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873
  1. #include "../pch/pch.h"
  2. #include "CSystemSettingWnd.h"
  3. #include "../control/ControlEx.h"
  4. #include "../tool/CComHelper.h"
  5. #include "CValueWnd.h"
  6. #include "../helper/CBitmapHelper.h"
  7. void CSystemSettingWnd::Init()
  8. {
  9. ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  10. m_nType = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_type").c_str());
  11. CHorizontalLayoutUI* com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num_layout")));
  12. CHorizontalLayoutUI* xuni_com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_layout")));
  13. CHorizontalLayoutUI* chuangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_layout")));
  14. CHorizontalLayoutUI* ocr_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_layout")));
  15. if (m_nType == 1)
  16. {
  17. //选中串口抓取
  18. CCheckBoxUI* zhuaquTypeOption = static_cast<CCheckBoxUI*>(m_pm.FindControl(L"jinezhuaqu_setting_chuankou"));
  19. zhuaquTypeOption->Selected(true, false);
  20. //显示串口设置
  21. com_layout->SetVisible(true);
  22. xuni_com_layout->SetVisible(false);
  23. chuangkou_layout->SetVisible(false);
  24. ocr_layout->SetVisible(false);
  25. }
  26. else if (m_nType == 2)
  27. {
  28. //选中虚拟串口抓取
  29. CCheckBoxUI* zhuaquTypeOption = static_cast<CCheckBoxUI*>(m_pm.FindControl(L"jinezhuaqu_setting_xunichuankou"));
  30. zhuaquTypeOption->Selected(true, false);
  31. //显示虚拟串口设置
  32. com_layout->SetVisible(false);
  33. xuni_com_layout->SetVisible(true);
  34. chuangkou_layout->SetVisible(false);
  35. ocr_layout->SetVisible(false);
  36. }
  37. else if (m_nType == 3)
  38. {
  39. CCheckBoxUI* zhuaquTypeOption = static_cast<CCheckBoxUI*>(m_pm.FindControl(L"jinezhuaqu_setting_chuangkou"));
  40. zhuaquTypeOption->Selected(true, false);
  41. //显示窗口截取的设置
  42. com_layout->SetVisible(false);
  43. xuni_com_layout->SetVisible(false);
  44. chuangkou_layout->SetVisible(true);
  45. ocr_layout->SetVisible(false);
  46. }
  47. else if (m_nType == 4)
  48. {
  49. CCheckBoxUI* zhuaquTypeOption = static_cast<CCheckBoxUI*>(m_pm.FindControl(L"jinezhuaqu_setting_ocr"));
  50. zhuaquTypeOption->Selected(true, false);
  51. //显示OCR的设置
  52. com_layout->SetVisible(false);
  53. xuni_com_layout->SetVisible(false);
  54. chuangkou_layout->SetVisible(false);
  55. ocr_layout->SetVisible(true);
  56. }
  57. //串口模式设置的初始化
  58. CComboUI* com_com = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num")));
  59. com_com->RemoveAll();
  60. //数据库中保存的之前的设置
  61. std::string s_jinezhuaqu_setting_chuankou_num = CSetting::GetParam("system_setting_jinezhuaqu_setting_chuankou_num");
  62. std::wstring ws_jinezhuaqu_setting_chuankou_num = CLewaimaiString::UTF8ToUnicode(s_jinezhuaqu_setting_chuankou_num);
  63. CComHelper helper;
  64. std::vector<std::wstring> comVector = helper.getComPort();
  65. int i = 0;
  66. int nSelect = -1;
  67. for (std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
  68. {
  69. CListLabelElementUI* elem = new CListLabelElementUI();
  70. elem->SetText((*it).c_str());
  71. com_com->Add(elem);
  72. if (*it == ws_jinezhuaqu_setting_chuankou_num)
  73. {
  74. nSelect = i;
  75. }
  76. i++;
  77. }
  78. com_com->SetInternVisible(true);
  79. com_com->SelectItem(nSelect, false, false);
  80. com_com->SetText(CLewaimaiString::UTF8ToUnicode(s_jinezhuaqu_setting_chuankou_num).c_str());
  81. //虚拟串口模式设置的初始化
  82. CComboUI* xuni_com_1 = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_1")));
  83. xuni_com_1->RemoveAll();
  84. CComboUI* xuni_com_2 = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_2")));
  85. xuni_com_2->RemoveAll();
  86. CComboUI* xuni_com_botelv = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_botelv")));
  87. //数据库中保存的之前的设置
  88. std::string s_system_setting_jinezhuaqu_setting_xunichuankou_num_1 = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_num_1");
  89. std::wstring ws_system_setting_jinezhuaqu_setting_xunichuankou_num_1 = CLewaimaiString::UTF8ToUnicode(s_system_setting_jinezhuaqu_setting_xunichuankou_num_1);
  90. std::string s_system_setting_jinezhuaqu_setting_xunichuankou_num_2 = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_num_2");
  91. std::wstring ws_system_setting_jinezhuaqu_setting_xunichuankou_num_2 = CLewaimaiString::UTF8ToUnicode(s_system_setting_jinezhuaqu_setting_xunichuankou_num_2);
  92. std::string s_system_setting_jinezhuaqu_setting_xunichuankou_botelv = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_botelv");
  93. std::wstring ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv = CLewaimaiString::UTF8ToUnicode(s_system_setting_jinezhuaqu_setting_xunichuankou_botelv);
  94. i = 0;
  95. nSelect = -1;
  96. for (std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
  97. {
  98. CListLabelElementUI* elem = new CListLabelElementUI();
  99. elem->SetText((*it).c_str());
  100. xuni_com_1->Add(elem);
  101. if (*it == ws_system_setting_jinezhuaqu_setting_xunichuankou_num_1)
  102. {
  103. nSelect = i;
  104. }
  105. i++;
  106. }
  107. xuni_com_1->SetInternVisible(true);
  108. xuni_com_1->SelectItem(nSelect, false, false);
  109. xuni_com_1->SetText(CLewaimaiString::UTF8ToUnicode(s_system_setting_jinezhuaqu_setting_xunichuankou_num_1).c_str());
  110. i = 0;
  111. nSelect = -1;
  112. for (std::vector<std::wstring>::iterator it = comVector.begin(); it != comVector.end(); it++)
  113. {
  114. CListLabelElementUI* elem = new CListLabelElementUI();
  115. elem->SetText((*it).c_str());
  116. xuni_com_2->Add(elem);
  117. if (*it == ws_system_setting_jinezhuaqu_setting_xunichuankou_num_2)
  118. {
  119. nSelect = i;
  120. }
  121. i++;
  122. }
  123. xuni_com_2->SetInternVisible(true);
  124. xuni_com_2->SelectItem(nSelect, false, false);
  125. xuni_com_2->SetText(CLewaimaiString::UTF8ToUnicode(s_system_setting_jinezhuaqu_setting_xunichuankou_num_2).c_str());
  126. xuni_com_botelv->SetInternVisible(true);
  127. if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"2400")
  128. {
  129. xuni_com_botelv->SelectItem(0, false, false);
  130. }
  131. else if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"4800")
  132. {
  133. xuni_com_botelv->SelectItem(1, false, false);
  134. }
  135. else if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"9600")
  136. {
  137. xuni_com_botelv->SelectItem(2, false, false);
  138. }
  139. else if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"19200")
  140. {
  141. xuni_com_botelv->SelectItem(3, false, false);
  142. }
  143. else if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"38400")
  144. {
  145. xuni_com_botelv->SelectItem(4, false, false);
  146. }
  147. else if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"57600")
  148. {
  149. xuni_com_botelv->SelectItem(5, false, false);
  150. }
  151. else if (ws_system_setting_jinezhuaqu_setting_xunichuankou_botelv == L"115200")
  152. {
  153. xuni_com_botelv->SelectItem(6, false, false);
  154. }
  155. xuni_com_botelv->SetText(CLewaimaiString::UTF8ToUnicode(s_system_setting_jinezhuaqu_setting_xunichuankou_botelv).c_str());
  156. //窗口模式设置的初始化
  157. CComboUI* find_wnd_type = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_model")));
  158. find_wnd_type->SetInternVisible(true);
  159. CHorizontalLayoutUI* chazhao_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_select_value_layout")));
  160. CHorizontalLayoutUI* dingwei_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_dingwei_value_layout")));
  161. std::string system_setting_jinezhuaqu_setting_chuangkou_model = CSetting::GetParam("system_setting_jinezhuaqu_setting_chuangkou_model");
  162. if (system_setting_jinezhuaqu_setting_chuangkou_model == "1")
  163. {
  164. //查找金额模式
  165. chazhao_layout->SetVisible(true);
  166. dingwei_layout->SetVisible(false);
  167. find_wnd_type->SelectItem(0, false, false);
  168. find_wnd_type->SetText(L"查找金额模式");
  169. }
  170. else
  171. {
  172. chazhao_layout->SetVisible(false);
  173. dingwei_layout->SetVisible(true);
  174. find_wnd_type->SelectItem(1, false, false);
  175. find_wnd_type->SetText(L"定位金额模式");
  176. }
  177. }
  178. LRESULT CSystemSettingWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  179. {
  180. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  181. styleValue &= ~WS_CAPTION;
  182. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  183. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  184. m_pm.Init(m_hWnd);
  185. m_pm.AddPreMessageFilter(this);
  186. //页面内有自定义控件的,必须要加这2个
  187. CDialogBuilder builder;
  188. CDialogBuilderCallbackEx cb;
  189. CControlUI* pRoot = builder.Create(_T("system_setting.xml"), (UINT)0, &cb, &m_pm);
  190. ASSERT(pRoot && "Failed to parse XML");
  191. // 把这些控件绘制到本窗口上
  192. m_pm.AttachDialog(pRoot);
  193. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  194. m_pm.AddNotifier(this);
  195. Init();
  196. return 0;
  197. }
  198. LRESULT CSystemSettingWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  199. {
  200. POINT pt;
  201. pt.x = GET_X_LPARAM(lParam);
  202. pt.y = GET_Y_LPARAM(lParam);
  203. ::ScreenToClient(*this, &pt);
  204. RECT rcClient;
  205. ::GetClientRect(*this, &rcClient);
  206. RECT rcCaption = m_pm.GetCaptionRect();
  207. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  208. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  209. {
  210. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  211. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  212. {
  213. return HTCAPTION;
  214. }
  215. }
  216. return HTCLIENT;
  217. }
  218. LRESULT CSystemSettingWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  219. {
  220. SIZE szRoundCorner = m_pm.GetRoundCorner();
  221. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  222. {
  223. CDuiRect rcWnd;
  224. ::GetWindowRect(*this, &rcWnd);
  225. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  226. rcWnd.right++;
  227. rcWnd.bottom++;
  228. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  229. ::SetWindowRgn(*this, hRgn, TRUE);
  230. ::DeleteObject(hRgn);
  231. }
  232. bHandled = FALSE;
  233. return 0;
  234. }
  235. LRESULT CSystemSettingWnd::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  236. {
  237. //先按控制键
  238. if (m_is_kuaijiepan_page)
  239. {
  240. if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN)
  241. {
  242. if (wParam != VK_CONTROL && wParam != VK_MENU && wParam != VK_SHIFT)
  243. {
  244. //这个情况,按的是字母键之类的
  245. CDuiString duiText;
  246. if (VK_F1 <= wParam && wParam <= VK_F12)
  247. {
  248. //快捷键就是F1到F12,不需要搭配ctrl之类的
  249. m_mod = 0;
  250. duiText.Format(_T("F%d"), wParam - VK_F1 + 1);
  251. }
  252. else if(m_mod == MOD_CONTROL)
  253. {
  254. duiText.Format(_T("CTRL + %c"), wParam);
  255. }
  256. else if (m_mod == MOD_ALT)
  257. {
  258. duiText.Format(_T("ALT + %c"), wParam);
  259. }
  260. else if(m_mod == MOD_SHIFT)
  261. {
  262. duiText.Format(_T("SHIFT + %c"), wParam);
  263. }
  264. else if(m_mod == 0)
  265. {
  266. //直接按的字母键,无效
  267. m_mod = 0;
  268. m_vk = 0;
  269. m_isSet = false;
  270. bHandled = TRUE;;
  271. return 0;
  272. }
  273. //到这里来设置成功了,做展示
  274. if (m_kuaijiejian_type == 1)
  275. {
  276. CEditUI* focusEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("kuaijiejian_setting_jiesuan_btn")));
  277. focusEdit->SetText(duiText);
  278. }
  279. m_vk = wParam;
  280. m_isSet = true;
  281. }
  282. else
  283. {
  284. //按的是控制键,这里只支持3选1,不能更多组合
  285. if (wParam == VK_CONTROL)
  286. {
  287. m_mod = MOD_CONTROL;
  288. }
  289. else if (wParam == VK_MENU)
  290. {
  291. m_mod = MOD_ALT;
  292. }
  293. else if(wParam == VK_SHIFT)
  294. {
  295. m_mod = MOD_SHIFT;
  296. }
  297. m_isSet = false;
  298. }
  299. }
  300. else if(uMsg == WM_KEYUP || uMsg == WM_SYSKEYUP)
  301. {
  302. //这个是只按了控制键,没有按其他的键
  303. if (!m_isSet)
  304. {
  305. if (wParam == VK_CONTROL)
  306. {
  307. m_mod = 0;
  308. }
  309. else if (wParam == VK_MENU)
  310. {
  311. m_mod = 0;
  312. }
  313. else if(wParam == VK_SHIFT)
  314. {
  315. m_mod = 0;
  316. }
  317. }
  318. else
  319. {
  320. //这里表示已经设置好了,等后面保存
  321. }
  322. return 0;
  323. }
  324. }
  325. bHandled = TRUE;
  326. return 0;
  327. }
  328. LRESULT CSystemSettingWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  329. {
  330. LRESULT lRes = 0;
  331. BOOL bHandled = TRUE;
  332. switch (uMsg)
  333. {
  334. case WM_CREATE:
  335. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  336. break;
  337. case WM_NCACTIVATE:
  338. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  339. break;
  340. case WM_NCCALCSIZE:
  341. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  342. break;
  343. case WM_NCPAINT:
  344. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  345. break;
  346. case WM_NCHITTEST:
  347. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  348. break;
  349. case WM_SIZE:
  350. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  351. break;
  352. case WM_KEYDOWN:
  353. lRes = OnKeyDown(uMsg, wParam, lParam, bHandled);
  354. break;
  355. case WM_SYSKEYDOWN:
  356. lRes = OnKeyDown(uMsg, wParam, lParam, bHandled);
  357. break;
  358. default:
  359. bHandled = FALSE;
  360. }
  361. if (bHandled)
  362. {
  363. return lRes;
  364. }
  365. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  366. {
  367. return lRes;
  368. }
  369. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  370. }
  371. LRESULT CSystemSettingWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  372. {
  373. if (uMsg == WM_KEYDOWN)
  374. {
  375. if (wParam == VK_RETURN)
  376. {
  377. return true;
  378. }
  379. else if (wParam == VK_ESCAPE)
  380. {
  381. return true;
  382. }
  383. }
  384. return false;
  385. }
  386. void CSystemSettingWnd::Notify(TNotifyUI& msg)
  387. {
  388. if (msg.sType == _T("windowinit"))
  389. {
  390. OnPrepare();
  391. }
  392. else if (msg.sType == _T("click"))
  393. {
  394. HandleClickMsg(msg);
  395. }
  396. else if (msg.sType == _T("selectchanged"))
  397. {
  398. HandleSelectChangeMsg(msg);
  399. }
  400. else if (msg.sType == _T("itemclick"))
  401. {
  402. }
  403. else if (msg.sType == _T("itemactivate"))
  404. {
  405. }
  406. else if (msg.sType == _T("itemselect"))
  407. {
  408. HandleItemSelectMsg(msg);
  409. }
  410. else if (msg.sType == _T("setfocus"))
  411. {
  412. if (msg.pSender->GetName() == L"kuaijiejian_setting_jiesuan_edit")
  413. {
  414. SetFocus(m_hWnd);
  415. }
  416. }
  417. }
  418. void CSystemSettingWnd::HandleClickMsg(TNotifyUI& msg)
  419. {
  420. DuiLib::CDuiString senderName = msg.pSender->GetName();
  421. if (senderName == _T("system_setting_closebtn"))
  422. {
  423. Close(IDCANCEL);
  424. return;
  425. }
  426. else if (senderName == _T("jinezhuaqu_setting_chuangkou_select_value_search"))
  427. {
  428. CEditUI* value = static_cast<CEditUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_select_value")));
  429. std::wstring search_value = value->GetText();
  430. FindValueWnd(search_value);
  431. }
  432. else if (senderName == _T("jinezhuaqu_setting_chuangkou_dingwei_value_btn"))
  433. {
  434. //点这个按钮之后,开始搜索窗口
  435. m_valueWnd->StartDingweiWnd();
  436. }
  437. else if (senderName == _T("jinezhuaqu_setting_ocr_select_value_search"))
  438. {
  439. //点了这个之后,开始截取屏幕
  440. m_valueWnd->StartOcrWnd();
  441. }
  442. else if (senderName == _T("jinezhuaqu_setting_save"))
  443. {
  444. //首先保存截取模式
  445. CSetting::SetParam("system_setting_jinezhuaqu_setting_type", to_string(m_nType).c_str(), false);
  446. if (m_nType == 1)
  447. {
  448. //保存串口参数
  449. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num")));
  450. wstring com_name = com->GetText();
  451. CSetting::SetParam("system_setting_jinezhuaqu_setting_chuankou_num", CLewaimaiString::UnicodeToUTF8(com_name));
  452. }
  453. else if (m_nType == 2)
  454. {
  455. //保存虚拟串口参数
  456. CComboUI* com_1 = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_1")));
  457. wstring com_name_1 = com_1->GetText();
  458. CSetting::SetParam("system_setting_jinezhuaqu_setting_xunichuankou_num_1", CLewaimaiString::UnicodeToUTF8(com_name_1));
  459. CComboUI* com_2 = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_2")));
  460. wstring com_name_2 = com_2->GetText();
  461. CSetting::SetParam("system_setting_jinezhuaqu_setting_xunichuankou_num_2", CLewaimaiString::UnicodeToUTF8(com_name_2));
  462. CComboUI* com_botelv = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_botelv")));
  463. wstring com_name_botelv = com_botelv->GetText();
  464. CSetting::SetParam("system_setting_jinezhuaqu_setting_xunichuankou_botelv", CLewaimaiString::UnicodeToUTF8(com_name_botelv));
  465. }
  466. else if (m_nType == 3)
  467. {
  468. //保存窗口监听的参数
  469. if (g_valuewnd_vector.size() == 0)
  470. {
  471. //没有合适的窗口
  472. MessageBox(m_hWnd, _T("没有找到合适的窗口,无法保存"), _T("提示"), MB_OK);
  473. return;
  474. }
  475. else
  476. {
  477. //找到合适的窗口了
  478. ValueWnd newWnd = g_valuewnd_vector[0];
  479. CSetting::SetParam("system_setting_jinezhuaqu_setting_chuangkou_process_name", CLewaimaiString::UnicodeToUTF8(newWnd.processName));
  480. CSetting::SetParam("system_setting_jinezhuaqu_setting_chuangkou_title", newWnd.wndTitle);
  481. CSetting::SetParam("system_setting_jinezhuaqu_setting_chuangkou_zorder", to_string(newWnd.z_order));
  482. CComboUI* find_wnd_type = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_model")));
  483. if (find_wnd_type->GetCurSel() == 0)
  484. {
  485. CSetting::SetParam("system_setting_jinezhuaqu_setting_chuangkou_model", "1");
  486. }
  487. else
  488. {
  489. CSetting::SetParam("system_setting_jinezhuaqu_setting_chuangkou_model", "2");
  490. }
  491. }
  492. }
  493. else if (m_nType == 4)
  494. {
  495. if (IsRectEmpty(&m_ocrRect))
  496. {
  497. MessageBox(m_hWnd, _T("没有设置OCR区域,无法保存"), _T("提示"), MB_OK);
  498. return;
  499. }
  500. else
  501. {
  502. CSetting::SetParam("system_setting_jinezhuaqu_setting_ocr_left", to_string(m_ocrRect.left).c_str());
  503. CSetting::SetParam("system_setting_jinezhuaqu_setting_ocr_top", to_string(m_ocrRect.top).c_str());
  504. CSetting::SetParam("system_setting_jinezhuaqu_setting_ocr_right", to_string(m_ocrRect.right).c_str());
  505. CSetting::SetParam("system_setting_jinezhuaqu_setting_ocr_bottom", to_string(m_ocrRect.bottom).c_str());
  506. }
  507. }
  508. //给监视窗口发个消息
  509. m_valueWnd->RestartWatch();
  510. }
  511. else if (senderName == _T("kuaijiejian_setting_jiesuan_btn"))
  512. {
  513. m_kuaijiejian_type = 1;
  514. m_mod = 0;
  515. m_vk = 0;
  516. m_isSet = false;
  517. }
  518. }
  519. void CSystemSettingWnd::HandleSelectChangeMsg(TNotifyUI& msg)
  520. {
  521. CDuiString name = msg.pSender->GetName();
  522. //先判断主页面的tab
  523. if (name == _T("system_setting_option_zhuaqu"))
  524. {
  525. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  526. if (pControl && pControl->GetCurSel() != 0)
  527. {
  528. pControl->SelectItem(0);
  529. }
  530. }
  531. else if (name == _T("system_setting_option_kuaijiejian"))
  532. {
  533. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  534. if (pControl && pControl->GetCurSel() != 1)
  535. {
  536. pControl->SelectItem(1);
  537. }
  538. m_is_kuaijiepan_page = true;
  539. }
  540. else if (name == _T("system_setting_option_about"))
  541. {
  542. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  543. if (pControl && pControl->GetCurSel() != 2)
  544. {
  545. pControl->SelectItem(2);
  546. }
  547. }
  548. else if (name == _T("jinezhuaqu_setting_chuankou"))
  549. {
  550. CHorizontalLayoutUI* com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num_layout")));
  551. CHorizontalLayoutUI* xuni_com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_layout")));
  552. CHorizontalLayoutUI* chuangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_layout")));
  553. CHorizontalLayoutUI* ocr_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_layout")));
  554. com_layout->SetVisible(true);
  555. xuni_com_layout->SetVisible(false);
  556. chuangkou_layout->SetVisible(false);
  557. ocr_layout->SetVisible(false);
  558. m_nType = 1;
  559. }
  560. else if (name == _T("jinezhuaqu_setting_xunichuankou"))
  561. {
  562. CHorizontalLayoutUI* com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num_layout")));
  563. CHorizontalLayoutUI* xuni_com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_layout")));
  564. CHorizontalLayoutUI* chuangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_layout")));
  565. CHorizontalLayoutUI* ocr_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_layout")));
  566. com_layout->SetVisible(false);
  567. xuni_com_layout->SetVisible(true);
  568. chuangkou_layout->SetVisible(false);
  569. ocr_layout->SetVisible(false);
  570. m_nType = 2;
  571. }
  572. else if (name == _T("jinezhuaqu_setting_chuangkou"))
  573. {
  574. CHorizontalLayoutUI* com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num_layout")));
  575. CHorizontalLayoutUI* xuni_com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_layout")));
  576. CHorizontalLayoutUI* chuangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_layout")));
  577. CHorizontalLayoutUI* ocr_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_layout")));
  578. com_layout->SetVisible(false);
  579. xuni_com_layout->SetVisible(false);
  580. chuangkou_layout->SetVisible(true);
  581. ocr_layout->SetVisible(false);
  582. m_nType = 3;
  583. }
  584. else if (name == _T("jinezhuaqu_setting_ocr"))
  585. {
  586. CHorizontalLayoutUI* com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuankou_num_layout")));
  587. CHorizontalLayoutUI* xuni_com_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_xunichuankou_num_layout")));
  588. CHorizontalLayoutUI* chuangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_layout")));
  589. CHorizontalLayoutUI* ocr_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_layout")));
  590. com_layout->SetVisible(false);
  591. xuni_com_layout->SetVisible(false);
  592. chuangkou_layout->SetVisible(false);
  593. ocr_layout->SetVisible(true);
  594. m_nType = 4;
  595. }
  596. }
  597. void CSystemSettingWnd::HandleItemSelectMsg(TNotifyUI& msg)
  598. {
  599. CDuiString name = msg.pSender->GetName();
  600. if (name == _T("jinezhuaqu_setting_chuangkou_model"))
  601. {
  602. CHorizontalLayoutUI* chazhao_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_select_value_layout")));
  603. CHorizontalLayoutUI* dingwei_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_dingwei_value_layout")));
  604. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_model")));
  605. if (com->GetCurSel() == 0)
  606. {
  607. //查找金额模式
  608. chazhao_layout->SetVisible(true);
  609. dingwei_layout->SetVisible(false);
  610. CSetting::SetParam("setting_printer_guige", "1");
  611. }
  612. else
  613. {
  614. chazhao_layout->SetVisible(false);
  615. dingwei_layout->SetVisible(true);
  616. CSetting::SetParam("setting_printer_guige", "2");
  617. }
  618. }
  619. }
  620. void CSystemSettingWnd::FindValueWnd(std::wstring value)
  621. {
  622. g_valuewnd_vector.clear();
  623. //先查找子窗口
  624. EnumWindows(EnumWindowsProc, (LPARAM)(&value));
  625. //展示查找结果
  626. int nCount = (int)g_valuewnd_vector.size();
  627. CHorizontalLayoutUI* result_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_select_value_search_result_layout")));
  628. result_layout->SetVisible(true);
  629. CLabelUI* result_label = static_cast<CLabelUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_select_value_search_result")));
  630. std::wstring result = L"共找到 " + to_wstring(nCount) + L" 个窗口";
  631. result_label->SetText(result.c_str());
  632. }
  633. void CSystemSettingWnd::FindDingweiWnd(HWND hWnd)
  634. {
  635. g_valuewnd_vector.clear();
  636. //先查找子窗口
  637. EnumWindows(EnumWindowsDingweiProc, (LPARAM)(hWnd));
  638. }
  639. void CSystemSettingWnd::SetDingweiWnd(std::wstring value, HWND hWnd)
  640. {
  641. std::string s_value = CLewaimaiString::UnicodeToUTF8(value);
  642. if (s_value == "" || !atof(s_value.c_str()))
  643. {
  644. CEditUI* dingwei_value_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_dingwei_value")));
  645. dingwei_value_edit->SetText(L"无有效金额");
  646. hWnd = NULL;
  647. }
  648. else
  649. {
  650. CEditUI* dingwei_value_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_chuangkou_dingwei_value")));
  651. std::wstring info = L"有效金额:" + value + L" 元";
  652. dingwei_value_edit->SetText(info.c_str());
  653. }
  654. m_DingweiWnd = hWnd;
  655. if (m_DingweiWnd == NULL)
  656. {
  657. return;
  658. }
  659. //找到定位的窗口的位置信息
  660. FindDingweiWnd(m_DingweiWnd);
  661. }
  662. void CSystemSettingWnd::SetOcrWnd(RECT rect)
  663. {
  664. //先把确认的区域保存下来
  665. m_ocrRect = rect;
  666. if (IsRectEmpty(&rect))
  667. {
  668. return;
  669. }
  670. //开始识别;
  671. CBitmapHelper helper;
  672. //先截屏
  673. HBITMAP h_bitmap = helper.CopyScreenToBitmap(&m_ocrRect);
  674. //将被截图的进行缩放,用于预览展示
  675. HBITMAP h_show_bitmap = helper.Scale(h_bitmap, 320, 200);
  676. DeleteObject(h_bitmap);
  677. //获得缩放后的图像的信息
  678. BITMAP Bitmap;
  679. GetObject(h_show_bitmap, sizeof(BITMAP), (LPSTR)&Bitmap);
  680. CControlUI* preview = static_cast<CControlUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_select_value_search_result_img")));
  681. //先删除旧的图片
  682. std::wstring oldImage = preview->GetBkImage();
  683. m_pm.RemoveImage(oldImage.c_str());
  684. //准备替换新的图片
  685. std::srand((unsigned int)time(NULL));
  686. std::wstring image_name = to_wstring(std::rand());
  687. //图片名字一定要每次不一样,不然不会更新
  688. std::wstring newImage = _T("jinezhuaqu_setting_ocr_select_value_search_result_img_") + image_name;
  689. m_pm.AddImage(newImage.c_str(), h_show_bitmap, Bitmap.bmWidth, Bitmap.bmHeight, false);
  690. preview->SetBkImage(newImage.c_str());
  691. preview->SetFixedWidth(Bitmap.bmWidth);
  692. preview->SetFixedHeight(Bitmap.bmHeight);
  693. std::string ocr_result;
  694. tesseract::TessBaseAPI tess;
  695. if (tess.Init("./tessdata", "eng"))
  696. {
  697. std::cout << "OCRTesseract: Could not initialize tesseract." << std::endl;
  698. }
  699. tess.SetPageSegMode(tesseract::PageSegMode::PSM_SINGLE_LINE);
  700. tess.SetVariable("save_best_choices", "T");
  701. bool ret = helper.OcrRect(tess, &m_ocrRect, ocr_result);
  702. //更新识别结果
  703. CEditUI* ocr_value_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("jinezhuaqu_setting_ocr_select_value")));
  704. if (!atof(ocr_result.c_str()))
  705. {
  706. //识别结果不是有效的数字
  707. ocr_value_edit->SetText(L"未识别到有效金额");
  708. }
  709. else
  710. {
  711. std::string format_value = CLewaimaiString::DoubleToString(atof(ocr_result.c_str()), 2);
  712. std::wstring ws_ocr_result = CLewaimaiString::UTF8ToUnicode(format_value);
  713. ocr_value_edit->SetText(ws_ocr_result.c_str());
  714. }
  715. }
  716. CEditUI* CSystemSettingWnd::GetFocusEdit()
  717. {
  718. CEditUI* jiesuan_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("kuaijiejian_setting_jiesuan_edit")));
  719. if (jiesuan_edit->IsFocused())
  720. {
  721. return jiesuan_edit;
  722. }
  723. return NULL;
  724. }