| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007 |
- #include "../pch/pch.h"
- #include "CValueWnd.h"
- #include "../tool/CComHelper.h"
- #include "../tool/CSerialPort.h"
- #include "../helper/CBitmapHelper.h"
- void CValueWnd::Notify(TNotifyUI& msg)
- {
- if(msg.sType == _T("click"))
- {
- if(msg.pSender->GetName() == _T("closebtn"))
- {
- PostQuitMessage(0);
- return;
- }
- }
- }
- void CValueWnd::Init()
- {
- //初始化窗口位置
- InitWndPos();
- //抢焦点
- std::thread(&CValueWnd::TopMostWnd, this).detach();
- //注册热键
- UpdateRegisterHotKey();
- //添加托盘图标
- AddTrayIcon();
- //初始化菜单窗口
- pMenu = new CMenuWnd(this);
- pMenu->Create(NULL, L"智铺子收银插件菜单", WS_POPUP, WS_EX_TOOLWINDOW);
- pMenu->ShowWindow(false);
- //定位窗口的初始化
- pDingweiWnd = new CDingweiWnd();
- pDingweiWnd->Create(NULL, _T("智铺子收银插件窗口定位"), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW, 0, 0, 0, 0, NULL);
- pDingweiWnd->ShowWindow(false);
- pDingweiInfoWnd = new CDingweiInfoWnd(this);
- pDingweiInfoWnd->Create(NULL, _T("智铺子收银插件窗口定位信息"), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW, 0, 0, 0, 0, NULL);
- pDingweiInfoWnd->ShowWindow(false);
- //Ocr窗口初始化
- pOcrWnd = new COcrWnd(this);
- pOcrWnd->Create(NULL, _T("智铺子收银插件OCR定位"), UI_WNDSTYLE_FRAME, WS_EX_TOOLWINDOW , 0, 0, 0, 0, NULL);
- pOcrWnd->ShowWindow(false);
- //OCR的数据初始化
- if (m_tess.Init("./tessdata", "eng"))
- {
- LOG_INFO("OCRTesseract: Could not initialize tesseract.");
- MessageBox(m_hWnd, L"ocr语言库加载失败", L"错误", MB_OK);
- }
- m_tess.SetPageSegMode(tesseract::PageSegMode::PSM_SINGLE_LINE);
- m_tess.SetVariable("save_best_choices", "T");
- //再安装钩子
- BOOL ret = InstallHook();
- //开始启动监听
- RestartWatch();
- }
- /*
- *抢窗口前端,抢焦点
- **/
- void CValueWnd::TopMostWnd()
- {
- while (true)
- {
- ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
- if (m_is_show_shoukuan && m_shoukuanHWND != NULL)
- {
- //::SendMessage(m_shoukuanHWND, WM_SHOUKUAN_UPDATE_FOCUS, NULL, NULL);
- }
- Sleep(300);
- }
- }
- void CValueWnd::RestartWatch()
- {
- std::thread(&CValueWnd::StartWatchWork, this).detach();
- }
- /*
- *根据当前数据库的设置,重启监听
- **/
- void CValueWnd::StartWatchWork()
- {
- //先暂停已有的监控
- m_isWatchWork = false;
- //等待2秒,这2秒就是等已有的监控线程自动退出
- Sleep(2000);
- //然后开始工作
- m_isWatchWork = true;
- std::string system_setting_jinezhuaqu_setting_type = CSetting::GetParam("system_setting_jinezhuaqu_setting_type");
- m_nWatchType = atoi(system_setting_jinezhuaqu_setting_type.c_str());
- if(m_nWatchType == 1)
- {
- //更新监听的端口号
- std::string system_setting_jinezhuaqu_setting_chuankou_num = CSetting::GetParam("system_setting_jinezhuaqu_setting_chuankou_num");
- if(system_setting_jinezhuaqu_setting_chuankou_num == "")
- {
- //参数错误
- return;
- }
- std::wstring ws_system_setting_jinezhuaqu_setting_chuankou_num = CLewaimaiString::UTF8ToUnicode(system_setting_jinezhuaqu_setting_chuankou_num);
- //设置窗口句柄
- ::SetHwnd(m_hWnd);
- //设置串口端口号
- std::transform(system_setting_jinezhuaqu_setting_chuankou_num.begin(), system_setting_jinezhuaqu_setting_chuankou_num.end(), system_setting_jinezhuaqu_setting_chuankou_num.begin(), ::toupper);
- std::transform(ws_system_setting_jinezhuaqu_setting_chuankou_num.begin(), ws_system_setting_jinezhuaqu_setting_chuankou_num.end(), ws_system_setting_jinezhuaqu_setting_chuankou_num.begin(), ::toupper);
- ::SetComNum(system_setting_jinezhuaqu_setting_chuankou_num.c_str(), ws_system_setting_jinezhuaqu_setting_chuankou_num.c_str(), system_setting_jinezhuaqu_setting_chuankou_num.size());
- }
- else if(m_nWatchType == 2)
- {
- //虚拟串口的模式
- std::thread(&CValueWnd::ReadXunichuankouValue, this).detach();
- }
- else if(m_nWatchType == 3)
- {
- //窗口模式
- m_watchWnd = NULL;
- std::thread(&CValueWnd::WatchWnd, this).detach();
- }
- else if (m_nWatchType == 4)
- {
- std::thread(&CValueWnd::StartOcrWork, this).detach();
- }
- }
- /*
- *读取客显金额的线程,一旦m_nWatchType不为2,那么就直接退出这个线程,下次设置的时候再开启
- **/
- void CValueWnd::ReadXunichuankouValue()
- {
- //读取虚拟串口的模式
- std::string system_setting_jinezhuaqu_setting_xunichuankou_num_2 = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_num_2");
- std::string system_setting_jinezhuaqu_setting_xunichuankou_botelv = CSetting::GetParam("system_setting_jinezhuaqu_setting_xunichuankou_botelv");
- CSerialPort serial(CLewaimaiString::UTF8ToUnicode(system_setting_jinezhuaqu_setting_xunichuankou_num_2), atoi(system_setting_jinezhuaqu_setting_xunichuankou_botelv.c_str()));
- bool ret = serial.openComm();
- if(!ret)
- {
- LOG_INFO("open com failed!");
- return;
- }
- char a[1024] = { 0 };
- //检查监控模式和波特率,如果变了就关闭掉
- while(m_nWatchType == 2 && m_isWatchWork)
- {
- memset(a, 0, 1024);
- //开始读取串口的数据
- DWORD nReaded = 0;
- serial.readFromComm(a, 1024, &nReaded);
- if(nReaded > 0)
- {
- UpdateKexian(a, nReaded);
- }
- Sleep(200);
- }
- serial.closeComm();
- }
- void CValueWnd::WatchWnd()
- {
- std::string system_setting_jinezhuaqu_setting_chuangkou_process_name = CSetting::GetParam("system_setting_jinezhuaqu_setting_chuangkou_process_name");
- std::string system_setting_jinezhuaqu_setting_chuangkou_title = CSetting::GetParam("system_setting_jinezhuaqu_setting_chuangkou_title");
- std::string system_setting_jinezhuaqu_setting_chuangkou_zorder = CSetting::GetParam("system_setting_jinezhuaqu_setting_chuangkou_zorder");
- //如果模式变了,或者参数变了,就退出(因为会重新启动一个新的监控)
- while(m_nWatchType == 3 && m_isWatchWork)
- {
- if(m_watchWnd != NULL)
- {
- std::wstring value;
- TCHAR szTitle[MAX_PATH] = { 0 };
- LPWSTR lpWindowName = szTitle;
- int ret = ::SendMessageW(m_watchWnd, WM_GETTEXT, (WPARAM)(MAX_PATH), (LPARAM)lpWindowName);
- if(ret == 0)
- {
- //说明m_watchWnd已经失效了
- value = L"0.00";
- m_watchWnd = NULL;
- }
- else
- {
- value = lpWindowName;
- //先对获取到的值做一下处理,删除掉人民币符号
- CLewaimaiString::Replace(value, L"¥", L"");
- }
- if(value != m_watchValue)
- {
- //保存下来窗口获取到的值
- m_watchValue = value;
- SendMessage(WM_WATCH_WND_UPDATE, NULL, NULL);
- }
- }
- else
- {
- //获得进程名字
- std::wstring processName = CLewaimaiString::UTF8ToUnicode(system_setting_jinezhuaqu_setting_chuangkou_process_name);
- //根据进程名字,找到对应的主窗口
- HWND mainWnd = GetWndHwnd(processName.c_str(), system_setting_jinezhuaqu_setting_chuangkou_title);
- if(mainWnd == NULL)
- {
- //说明这个进程还没有启动
- m_watchWnd = NULL;
- }
- else
- {
- //根据Z序查找目标窗口
- ValueWnd newWnd;
- newWnd.wndTitle = system_setting_jinezhuaqu_setting_chuangkou_title;
- newWnd.TopWnd = mainWnd;
- newWnd.z_order = atoi(system_setting_jinezhuaqu_setting_chuangkou_zorder.c_str());
- newWnd.processName = processName;
- newWnd.selfWnd = NULL;
- g_zorder = 0;
- EnumChildWindows(mainWnd, EnumMainwndChildProc, (LPARAM)(&newWnd));
- if(newWnd.selfWnd != NULL)
- {
- //找到了
- m_watchWnd = newWnd.selfWnd;
- }
- }
- }
- Sleep(200);
- }
- }
- void CValueWnd::StartOcrWork()
- {
- int system_setting_jinezhuaqu_setting_ocr_left = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_left").c_str());
- int system_setting_jinezhuaqu_setting_ocr_top = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_top").c_str());
- int system_setting_jinezhuaqu_setting_ocr_right = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_right").c_str());
- int system_setting_jinezhuaqu_setting_ocr_bottom = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_bottom").c_str());
- //如果模式变了,或者参数变了,就退出(因为会重新启动一个新的监控)
- while (m_nWatchType == 4 && m_isWatchWork)
- {
- RECT rect;
- rect.left = system_setting_jinezhuaqu_setting_ocr_left;
- rect.top = system_setting_jinezhuaqu_setting_ocr_top;
- rect.right = system_setting_jinezhuaqu_setting_ocr_right;
- rect.bottom = system_setting_jinezhuaqu_setting_ocr_bottom;
- if (IsRectEmpty(&rect))
- {
-
- }
- else
- {
- CBitmapHelper helper;
- std::string ocr_result;
- bool ret = helper.OcrRect(m_tess, &rect, ocr_result);
- if (ret)
- {
- if (!atof(ocr_result.c_str()))
- {
- //识别结果不是有效的数字
- CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
- valueLabel->SetText(L"0.00");
- }
- else
- {
- std::string format_value = CLewaimaiString::DoubleToString(atof(ocr_result.c_str()), 2);
- std::wstring ws_ocr_result = CLewaimaiString::UTF8ToUnicode(format_value);
- m_watchValue = ws_ocr_result;
- CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
- valueLabel->SetText(ws_ocr_result.c_str());
- }
- }
- }
- Sleep(200);
- }
- }
- LRESULT CValueWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
- styleValue &= ~WS_CAPTION;
- ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
- // 把自己的窗口句柄与窗口绘制管理器挂接在一起
- m_pm.Init(m_hWnd);
- m_pm.AddPreMessageFilter(this);
- CDialogBuilder builder;
- CControlUI* pRoot = builder.Create(_T("value.xml"), (UINT)0, NULL, &m_pm);
- ASSERT(pRoot && "Failed to parse XML");
- // 把这些控件绘制到本窗口上
- m_pm.AttachDialog(pRoot);
- // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
- m_pm.AddNotifier(this);
- //进行一些初始化工作
- Init();
- return 0;
- }
- LRESULT CValueWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- bHandled = FALSE;
- return 0;
- }
- /*
- *这个是窗口被销毁的时候调用的
- **/
- LRESULT CValueWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- UnregisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN);
- bHandled = FALSE;
- return 0;
- }
- LRESULT CValueWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- if(::IsIconic(*this))
- {
- bHandled = FALSE;
- }
- return (wParam == 0) ? TRUE : FALSE;
- }
- LRESULT CValueWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- return 0;
- }
- LRESULT CValueWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- return 0;
- }
- LRESULT CValueWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- POINT pt;
- pt.x = GET_X_LPARAM(lParam);
- pt.y = GET_Y_LPARAM(lParam);
- ::ScreenToClient(*this, &pt);
- RECT rcClient;
- ::GetClientRect(*this, &rcClient);
- RECT rcCaption = m_pm.GetCaptionRect();
- if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
- && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
- {
- CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
- if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
- {
- return HTCAPTION;
- }
- }
- return HTCLIENT;
- }
- LRESULT CValueWnd::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- pMenu->ShowWindow(false);
- bHandled = FALSE;
- return 0;
- }
- LRESULT CValueWnd::OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- RECT rect;
- GetWindowRect(m_hWnd, &rect);
- ::SetWindowPos(pMenu->GetHWND(), HWND_NOTOPMOST, rect.left, rect.bottom - 3, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
- pMenu->ShowWindow(true);
- //右击后点别地可以清除“右击出来的菜单”
- SetForegroundWindow(pMenu->GetHWND());
- bHandled = FALSE;
- return 0;
- }
- LRESULT CValueWnd::OnKexianUpdate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- //如果当前不是串口模式,直接忽略
- if(m_nWatchType != 1)
- {
- bHandled = TRUE;
- return true;
- }
- //收到了客显数据消息,读取客显数据
- char data[MAX_DATA_LENGTH] = { 0 };
- int data_length = 0;
- HookGetData(data, &data_length);
- if(data_length == 0)
- {
- bHandled = TRUE;
- return true;
- }
- UpdateKexian(data, data_length);
- bHandled = TRUE;
- return true;
- }
- LRESULT CValueWnd::OnWatchWndUpdate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
- std::string utf8_watch_value = CLewaimaiString::UnicodeToUTF8(m_watchValue);
- std::string money_show = CLewaimaiString::DoubleToString(atof(utf8_watch_value.c_str()), 2);
- valueLabel->SetText(CLewaimaiString::UTF8ToUnicode(money_show).c_str());
- return TRUE;
- }
- LRESULT CValueWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- LRESULT lRes = 0;
- BOOL bHandled = TRUE;
- switch(uMsg)
- {
- case WM_CREATE:
- lRes = OnCreate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_CLOSE:
- lRes = OnClose(uMsg, wParam, lParam, bHandled);
- break;
- case WM_DESTROY:
- lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCACTIVATE:
- lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCLBUTTONDOWN:
- lRes = OnLButtonDown(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCRBUTTONDOWN:
- lRes = OnRButtonDown(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCCALCSIZE:
- lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCPAINT:
- lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCHITTEST:
- lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
- break;
- case WM_SHOWTASK:
- lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
- break;
- case WM_HOOK_MESSAGE:
- lRes = OnKexianUpdate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_WATCH_WND_UPDATE:
- lRes = OnWatchWndUpdate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_HOTKEY:
- lRes = OnHotKey(uMsg, wParam, lParam, bHandled);
- break;
- default:
- bHandled = FALSE;
- }
- if(bHandled)
- {
- return lRes;
- }
- if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
- {
- return lRes;
- }
- return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
- }
- LRESULT CValueWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
- {
- return false;
- }
- void CValueWnd::ShowShoukuan()
- {
- if (m_is_show_shoukuan == true)
- {
- return;
- }
- pMenu->ShowWindow(false);
- CShoukuanWnd* pShoukuanWnd = new CShoukuanWnd;
- if (pShoukuanWnd != NULL)
- {
- pShoukuanWnd->Create(NULL, _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
- pShoukuanWnd->SetIcon(IDI_ICON_DUILIB);
- pShoukuanWnd->CenterWindow();
- ::SetWindowPos(pShoukuanWnd->GetHWND(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
- m_is_show_shoukuan = true;
- m_shoukuanWnd = pShoukuanWnd;
- m_shoukuanHWND = pShoukuanWnd->GetHWND();
- //只要金额不为0,就初始化
- std::string utf8_watch_value = CLewaimaiString::UnicodeToUTF8(m_watchValue);
- if (atof(utf8_watch_value.c_str()) > 0.001)
- {
- std::string format_string = CLewaimaiString::DoubleToString(atof(utf8_watch_value.c_str()), 2);
- m_watchValue = CLewaimaiString::UTF8ToUnicode(format_string);
- pShoukuanWnd->InitMoney(m_watchValue);
- }
- UINT ret = pShoukuanWnd->ShowModal();
- m_is_show_shoukuan = false;
- m_shoukuanWnd = NULL;
- m_shoukuanHWND = NULL;
- if (ret == IDOK)
- {
-
- }
- else if (ret == IDCANCEL)
- {
- }
- }
- }
- void CValueWnd::AddTrayIcon()
- {
- memset(&m_trayIcon, 0, sizeof(NOTIFYICONDATA));
- m_trayIcon.cbSize = sizeof(NOTIFYICONDATA);
- m_trayIcon.hIcon = ::LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON_DUILIB));
- m_trayIcon.hWnd = m_hWnd;
- lstrcpy(m_trayIcon.szTip, _T("智铺子收银插件"));
- m_trayIcon.uCallbackMessage = WM_SHOWTASK;
- m_trayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
- Shell_NotifyIcon(NIM_ADD, &m_trayIcon);
- }
- LRESULT CValueWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- //如果在图标中单击左键则还原
- if(lParam == WM_LBUTTONDOWN)
- {
- ShowTrayMenu();
- }
- //如果在图标中单击右键则弹出声明式菜单
- else if(lParam == WM_RBUTTONDOWN)
- {
- ShowTrayMenu();
- }
- bHandled = true;
- return 0;
- }
- LRESULT CValueWnd::OnHotKey(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- UINT fuModifiers = (UINT)LOWORD(lParam);
- UINT uVirtKey = (UINT)HIWORD(lParam);
- //判断响应了什么热键
- if (wParam == WM_MYHOTKEY_SHOUKUAN)
- {
- if (m_is_show_setting == false)
- {
- ShowShoukuan();
- }
- }
- bHandled = TRUE;
- return 0;
- }
- void CValueWnd::ShowSystemSetting()
- {
- //先隐藏目录
- pMenu->ShowWindow(false);
- //然后判断和显示系统设置
- if (m_is_show_setting == true)
- {
- return;
- }
- CSystemSettingWnd* pSystemSettingFrame = new CSystemSettingWnd(this);
- m_settingWnd = pSystemSettingFrame;
- if (pSystemSettingFrame != NULL)
- {
- m_is_show_setting = true;
- pSystemSettingFrame->Create(NULL, _T(""), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW);
- pSystemSettingFrame->SetIcon(IDI_ICON_DUILIB);
- pSystemSettingFrame->CenterWindow();
- UINT ret = pSystemSettingFrame->ShowModal();
- m_is_show_setting = false;
- if (ret == IDOK)
- {
- }
- else if (ret == IDCANCEL)
- {
- }
- }
- }
- void CValueWnd::UpdateKexian(const char* data, int length)
- {
- std::string new_data = data;
- //清屏命令
- std::string clear_command = "\f";
- //4个信号灯全灭
- std::string quanmie_command = "\x1bs0";
- std::string show_command = "\x1bQA";
- std::string show_command_2 = "QA";
- std::string type_command = "\x1bs";
- if(new_data == clear_command || new_data == quanmie_command)
- {
- //清屏命令,或者是熄灭灯的命令
- return;
- }
- int nShowType;
- if(new_data.find(show_command) == new_data.npos)
- {
- //没有\x1bQA,继续找有没有QA(比如思迅)
- if (new_data.find(show_command_2) == new_data.npos)
- {
- //完全没QA
- return;
- }
- else
- {
- nShowType = 2;
- }
- }
- else
- {
- nShowType = 1;
- }
- std::string money;
- int nPos;
-
- if (nShowType == 1)
- {
- nPos = new_data.find(show_command);;
- }
- else
- {
- nPos = new_data.find(show_command_2);
- }
- int nTypePos = new_data.find(type_command, nPos + 1);
- if(nTypePos == new_data.npos)
- {
- //没有类型信息,有些收银机(比如思迅天店)就是不传类型信息,这种只有传什么显示什么了
- int nTabPos = new_data.find("\r", nPos + 1);
- if(nTabPos == new_data.npos)
- {
- //制表符也没有
- return;
- }
- if (nShowType == 1)
- {
- money = new_data.substr(nPos + 3, nTabPos - nPos - 3);
- }
- else
- {
- money = new_data.substr(nPos + 2, nTabPos - nPos - 2);
- }
- CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
- std::string money_show = CLewaimaiString::DoubleToString(atof(money.c_str()), 2);
- m_watchValue = CLewaimaiString::UTF8ToUnicode(money_show);
- valueLabel->SetText(CLewaimaiString::UTF8ToUnicode(money_show).c_str());
- }
- else
- {
- std::string value_type = new_data.substr(nTypePos + 2, 1);
- money = new_data.substr(nPos + 3, nTypePos - nPos - 3 - 1);
- if(value_type == "2")
- {
- //这个表示是总计的,那么就要刷新金额显示
- CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
- std::string money_show = CLewaimaiString::DoubleToString(atof(money.c_str()), 2);
- m_watchValue = CLewaimaiString::UTF8ToUnicode(money_show);
- valueLabel->SetText(CLewaimaiString::UTF8ToUnicode(money_show).c_str());
- }
- else
- {
- //这种情况传输的是一些找零、单价之类的信息,不更新客显金额
- }
- }
- return;
- }
- void CValueWnd::InitWndPos()
- {
- ASSERT(::IsWindow(m_hWnd));
- ASSERT((GetWindowStyle(m_hWnd)&WS_CHILD) == 0);
- RECT rcDlg = { 0 };
- ::GetWindowRect(m_hWnd, &rcDlg);
- RECT rcArea = { 0 };
- RECT rcCenter = { 0 };
- HWND hWnd = *this;
- HWND hWndParent = ::GetParent(m_hWnd);
- HWND hWndCenter = ::GetWindowOwner(m_hWnd);
- if(hWndCenter != NULL)
- {
- hWnd = hWndCenter;
- }
- // 处理多显示器模式下屏幕居中
- MONITORINFO oMonitor = {};
- oMonitor.cbSize = sizeof(oMonitor);
- ::GetMonitorInfo(::MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST), &oMonitor);
- rcArea = oMonitor.rcWork;
- if(hWndCenter == NULL)
- {
- rcCenter = rcArea;
- }
- else
- {
- ::GetWindowRect(hWndCenter, &rcCenter);
- }
- int DlgWidth = rcDlg.right - rcDlg.left;
- int DlgHeight = rcDlg.bottom - rcDlg.top;
- int xLeft = rcCenter.right - DlgWidth - 60;
- int yTop = 100;
- if(xLeft < rcArea.left)
- {
- xLeft = rcArea.left;
- }
- else if(xLeft + DlgWidth > rcArea.right)
- {
- xLeft = rcArea.right - DlgWidth;
- }
- if(yTop < rcArea.top)
- {
- yTop = rcArea.top;
- }
- else if(yTop + DlgHeight > rcArea.bottom)
- {
- yTop = rcArea.bottom - DlgHeight;
- }
- ::SetWindowPos(m_hWnd, HWND_TOPMOST, xLeft, yTop, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
- }
- void CValueWnd::ShowTrayMenu()
- {
- //获取鼠标坐标
- POINT pt;
- GetCursorPos(&pt);
- CRect rect;
- GetWindowRect(pMenu->GetHWND(), &rect);
- int height = rect.bottom - rect.top;
- //显示目录
- ::SetWindowPos(pMenu->GetHWND(), HWND_NOTOPMOST, pt.x, pt.y - 15 - height, 0, 0, SWP_NOSIZE | SWP_NOACTIVATE);
- pMenu->ShowWindow(true);
- SetFocus(pMenu->GetHWND());
- //右击后点别地可以清除“右击出来的菜单”
- SetForegroundWindow(pMenu->GetHWND());
- }
- void CValueWnd::StartDingweiWnd()
- {
- m_settingWnd->ShowWindow(false);
- m_is_dingwei_wnd = true;
- std::thread(&CValueWnd::StartDingweiWork, this).detach();
- }
- void CValueWnd::ConfirmDingweiWnd(std::wstring value, HWND hWnd)
- {
- m_is_dingwei_wnd = false;
- m_settingWnd->SetDingweiWnd(value, hWnd);
- }
- void CValueWnd::CancalDingweiWnd()
- {
- m_is_dingwei_wnd = false;
- }
- void CValueWnd::StartDingweiWork()
- {
- while (m_is_dingwei_wnd)
- {
- //这个时候,是开始定位窗口了
- POINT pt;
- GetCursorPos(&pt);
- //将屏幕坐标保存起来
- POINT ptScreen = pt;
- //转换成桌面坐标
- HWND hDeskHandle = GetDesktopWindow();
- ScreenToClient(hDeskHandle, &pt);
- HWND hParent = hDeskHandle;
- HWND hChild = ChildWindowFromPointEx(hParent, pt, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT | CWP_SKIPDISABLED);
- if (hChild == pDingweiInfoWnd->GetHWND())
- {
- //这里表示是移动信息窗口了,这里就不要执行后面的刷新操作了
- }
- else
- {
- while (hChild != NULL && hChild != hParent)
- {
- //说明还有更下级的子窗口
- hParent = hChild;
- pt = ptScreen;
- ScreenToClient(hParent, &pt);
- hChild = ChildWindowFromPointEx(hParent, pt, CWP_SKIPINVISIBLE | CWP_SKIPTRANSPARENT);
- }
- HWND hWnd = hParent;
- RECT rect;
- GetWindowRect(hWnd, &rect);
- //在这个窗口上,画一个边框
- pDingweiWnd->ShowWindow(true);
- ::SetWindowPos(pDingweiWnd->GetHWND(), HWND_TOPMOST, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOACTIVATE);
- //显示定位信息
- TCHAR szTitle[MAX_PATH] = { 0 };
- LPWSTR lpWindowName = szTitle;
- ::SendMessageW(hWnd, WM_GETTEXT, (WPARAM)(MAX_PATH), (LPARAM)lpWindowName);
- //设置信息窗口的内容
- pDingweiInfoWnd->UpdateInfo(lpWindowName, hWnd);
- pDingweiInfoWnd->ShowWindow(true);
- ::SetWindowPos(pDingweiInfoWnd->GetHWND(), HWND_TOPMOST, rect.left, rect.bottom, rect.right - rect.left, 30, SWP_NOACTIVATE);
- }
- Sleep(100);
- }
- m_settingWnd->ShowWindow(true);
- pDingweiWnd->ShowWindow(false);
- pDingweiInfoWnd->ShowWindow(false);
- }
- void CValueWnd::StartOcrWnd()
- {
- m_settingWnd->ShowWindow(false);
- m_is_orc_wnd = true;
- pOcrWnd->ShowWindow(true);
- //先默认居中
- ::SetWindowPos(pOcrWnd->GetHWND(), HWND_TOPMOST, 0, 0, 320, 80, SWP_NOMOVE | SWP_NOACTIVATE);
- pOcrWnd->CenterWindow();
- }
- void CValueWnd::ConfirmOcrWnd(RECT rect)
- {
- m_is_orc_wnd = false;
- pOcrWnd->ShowWindow(false);
- //保存截屏的结果
- m_settingWnd->SetOcrWnd(rect);
- //显示设置窗口
- m_settingWnd->ShowWindow(true);
- }
- tesseract::TessBaseAPI& CValueWnd::GetTess()
- {
- return m_tess;
- }
- bool CValueWnd::UpdateRegisterHotKey()
- {
- UINT shoukuan_mod = (UINT)atoi(CSetting::GetParam("system_setting_kuaijiejian_shoukuan_mod").c_str());
- UINT shoukuan_vk = (UINT)atoi(CSetting::GetParam("system_setting_kuaijiejian_shoukuan_vk").c_str());
- //先卸载旧的,再注册新的
- UnregisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN);
- int nRet = RegisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN, shoukuan_mod, shoukuan_vk);
- return nRet;
- }
|