소스 검색

先备份一下,准备更换duilib

zhangyang 5 년 전
부모
커밋
15807c5f5e

+ 2 - 0
bin/Win32/Debug/zhipuzi_pay_plugin/skin/system_setting.xml

@@ -14,6 +14,8 @@
 				<Control bkimage="shop_logo.png" width="70" height="70" padding="48,20,0,10"></Control>
 				<Label name="system_setting_shopname" text="店铺名字店铺" font="0" width="140" height="60" padding="10,0,10,0" align="center" multiline="true" ></Label>
 				
+				<Button name="system_setting_logout" height="38" padding="20,20,20,0" text="退出登录" textcolor="#FFFFFFFF" normalimage="file='Btn_Red.png' corner='5,5,5,5'" hotimage="file='Btn_Red_Hover.png' corner='5,5,5,5'" pushedimage="file='Btn_Red_Click.png' corner='5,5,5,5'"/>
+				
 				<Control width="160" height="1" bkcolor="#FFE0E0E6" padding="0,25,0,25"></Control>
 				
 				<Option name="system_setting_option_zhuaqu" text="金额抓取" font="0" group="system_setting_item" selected="true" height="40" hotimage="tab_hot.bmp" selectedimage="setting_tab_bkg.png" selectedtextcolor="0xFFFFFFFF"/>

+ 6 - 6
zhipuzi_pay_plugin/network/CMessagePush.cpp

@@ -21,6 +21,12 @@ void CMessagePush::Start()
 void CMessagePush::Stop()
 {
     m_is_work = false;
+
+	//一直等到真实的退出
+	while (m_nStopNum < 1)
+	{
+		Sleep(100);
+	}
 }
 
 void CMessagePush::AddPrinter(std::string out_order_no, int print_type)
@@ -114,10 +120,4 @@ void CMessagePush::AddStopNum()
     m_nStopNum++;
 
     m_nStopNumMutex.unlock();
-
-    if(m_nStopNum == 1)
-    {
-        //确认所有子线程都退出了,再删除自己
-        delete this;
-    }
 }

+ 12 - 0
zhipuzi_pay_plugin/network/CZhipuziHttpClient.cpp

@@ -158,6 +158,18 @@ bool CZhipuziHttpClient::Login(std::string& errmsg)
 	rapidjson::Value& v_lwm_sess_token = v_data["lwm_sess_token"];
 	m_client.lwm_sess_token = v_lwm_sess_token.GetString();
 
+	std::string shop_id = v_data["shop_id"].GetString();
+	std::string shopname = v_data["shopname"].GetString();;
+
+	if (shop_id == "0")
+	{
+		errmsg = CLewaimaiString::UnicodeToUTF8(L"该账号还未绑定收款店铺,无法登录!");
+
+		return false;
+	}
+
+	m_client.m_shopname = shopname;
+
     LOG_INFO("login success!");
 
     return true;

+ 1 - 1
zhipuzi_pay_plugin/wnd/CDingweiInfoWnd.h

@@ -22,7 +22,7 @@ public:
 	void OnFinalMessage(HWND /*hWnd*/)
 	{
 		//m_pm.RemovePreMessageFilter(this);
-		delete this;
+		//delete this;
 	};
 
 	void Init();

+ 1 - 1
zhipuzi_pay_plugin/wnd/CDingweiWnd.h

@@ -19,7 +19,7 @@ public:
 	void OnFinalMessage(HWND /*hWnd*/)
 	{
 		//m_pm.RemovePreMessageFilter(this);
-		delete this;
+		//delete this;
 	};
 
 	void Init();

+ 0 - 85
zhipuzi_pay_plugin/wnd/CLoginWnd.cpp

@@ -545,91 +545,6 @@ void CLoginWnd::HandleLogin()
 		//把用户名和密码保存起来
 		CSetting::SetLoginInfo(s_account, s_password);
 
-/*
-		//开始处理获取账号权限的逻辑
-		std::map<string, string> params;
-
-		params["version_type"] = CZhipuziHttpClient::m_client.m_version_type;
-		params["lwm_sess_token"] = CZhipuziHttpClient::m_client.lwm_sess_token;
-
-		std::string response;
-
-		std::string url = "/common/merchant/account/user/syncuserdata";
-		CZhipuziHttpClient::RequestNew(url.c_str(), params, response);
-
-		rapidjson::Document document;
-		document.Parse(response.c_str());
-
-		if (document.HasParseError())
-		{
-			pLoginResultLabel->SetText(std::wstring(_T("服务器错误")).c_str());
-			pLoginResultLabel->SetVisible(true);
-
-			PostMessage(WM_LOGIN_ERROR);
-
-			return;
-		}
-
-		if (document.HasMember("error_code"))
-		{
-			if (!document.HasMember("error_code") || !document.HasMember("error_msg") || !document.HasMember("data"))
-			{
-				pLoginResultLabel->SetText(std::wstring(_T("服务器错误")).c_str());
-				pLoginResultLabel->SetVisible(true);
-
-				PostMessage(WM_LOGIN_ERROR);
-
-				return;
-			}
-
-			rapidjson::Value& v_errcode = document["error_code"];
-			int errcode = v_errcode.GetInt();
-			if (errcode != 0)
-			{
-				std::string errmsg = document["error_msg"].GetString();
-
-				pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
-				pLoginResultLabel->SetVisible(true);
-
-				PostMessage(WM_LOGIN_ERROR);
-
-				return;
-			}
-		}
-		else if (document.HasMember("errcode"))
-		{
-			if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
-			{
-				pLoginResultLabel->SetText(std::wstring(_T("服务器错误")).c_str());
-				pLoginResultLabel->SetVisible(true);
-
-				PostMessage(WM_LOGIN_ERROR);
-
-				return;
-			}
-
-			rapidjson::Value& v_errcode = document["errcode"];
-			int errcode = v_errcode.GetInt();
-			if (errcode != 0)
-			{
-				std::string errmsg = document["errmsg"].GetString();
-
-				pLoginResultLabel->SetText(CLewaimaiString::UTF8ToUnicode(errmsg).c_str());
-				pLoginResultLabel->SetVisible(true);
-
-				PostMessage(WM_LOGIN_ERROR);
-
-				return;
-			}
-		}	
-
-		rapidjson::Value& data = document["data"];
-		rapidjson::Value& shop_name = data["shop_name"];
-
-		std::string shopname = shop_name.GetString();
-
-		CZhipuziHttpClient::m_client.m_shopname = shopname;*/
-
 		PostMessage(WM_LOGIN_SUCCESS);
 
 		return;

+ 3 - 1
zhipuzi_pay_plugin/wnd/CMenuWnd.cpp

@@ -27,7 +27,7 @@ void CMenuWnd::Notify(TNotifyUI& msg)
 	{
 		if (name == L"value_menu_quit")
 		{
-			PostQuitMessage(0);
+			m_valueWnd->QuitApp();
 		}
 		else if (name == L"value_menu_guanwang")
 		{
@@ -38,6 +38,8 @@ void CMenuWnd::Notify(TNotifyUI& msg)
 		else if (name == L"value_menu_shezhi")
 		{
 			m_valueWnd->ShowSystemSetting();
+
+			int a = 1;
 		}
 		else if (name == L"value_menu_shoukuan")
 		{

+ 1 - 1
zhipuzi_pay_plugin/wnd/CMenuWnd.h

@@ -21,7 +21,7 @@ public:
 	void OnFinalMessage(HWND /*hWnd*/)
 	{
 		//m_pm.RemovePreMessageFilter(this);
-		delete this;
+		//delete this;
 	};
 
 	void Init();

+ 1 - 1
zhipuzi_pay_plugin/wnd/COcrWnd.h

@@ -21,7 +21,7 @@ public:
 	void OnFinalMessage(HWND /*hWnd*/)
 	{
 		//m_pm.RemovePreMessageFilter(this);
-		delete this;
+		//delete this;
 	};
 
 	void Init();

+ 8 - 0
zhipuzi_pay_plugin/wnd/CSystemSettingWnd.cpp

@@ -957,6 +957,14 @@ void CSystemSettingWnd::HandleClickMsg(TNotifyUI& msg)
         m_vk = 0;
         m_isSet = false;
     }
+	else if (senderName == L"system_setting_logout")
+	{
+		//退出登录
+		m_is_logout = true;
+
+		Close(IDCANCEL);
+		return;
+	}
 }
 
 void CSystemSettingWnd::HandleSelectChangeMsg(TNotifyUI& msg)

+ 6 - 1
zhipuzi_pay_plugin/wnd/CSystemSettingWnd.h

@@ -28,7 +28,9 @@ public:
 	{
 		//WindowImplBase::OnFinalMessage(hWnd);
 		m_pm.RemovePreMessageFilter(this);
-		delete this;
+
+		//这里不要调用delte,后面手动delete,如果自动delete了,窗口关闭后的逻辑不好处理
+		//delete this;
 	};
 
 	void Init();
@@ -86,6 +88,9 @@ private:
 public:
 	CPaintManagerUI m_pm;
 
+	//表示是否是通过退出登录关闭的
+	bool m_is_logout = false;
+
 private:
 	CValueWnd* m_valueWnd;
 

+ 128 - 29
zhipuzi_pay_plugin/wnd/CValueWnd.cpp

@@ -11,18 +11,7 @@
 
 #include <atltypes.h>
 
-void RegKeyboardRawInput(HWND hWnd)
-{
-	RAWINPUTDEVICE rawInputDevice[1];
-	rawInputDevice[0].usUsagePage = 0x01;//设备类
-	rawInputDevice[0].usUsage = 0x06;//设备类内的具体设备
-	rawInputDevice[0].dwFlags = RIDEV_INPUTSINK;//意味着即使窗口失去焦点位置,仍然会一直接收输入消息
-	rawInputDevice[0].hwndTarget = hWnd;
-	if (RegisterRawInputDevices(rawInputDevice, 1, sizeof(rawInputDevice[0])) == FALSE)
-	{
-		printf("RegisterRawInputDevices failed");
-	}
-}
+#include "CLoginWnd.h"
 
 void CValueWnd::Notify(TNotifyUI& msg)
 {
@@ -44,6 +33,9 @@ void CValueWnd::Init()
 	//抢焦点
 	std::thread(&CValueWnd::TopMostWnd, this).detach();
 
+	//任务+1
+	m_nTaskNum++;
+
 	//注册热键
 	UpdateRegisterHotKey();
 
@@ -83,13 +75,14 @@ void CValueWnd::Init()
 	m_tess.SetPageSegMode(tesseract::PageSegMode::PSM_SINGLE_LINE);
 	m_tess.SetVariable("save_best_choices", "T");
 
+	//开启键盘输入监听
+	RegKeyboardRawInput();
+
     //再安装钩子
     BOOL ret = InstallHook();
 
     //开始启动监听
     RestartWatch();
-
-	RegKeyboardRawInput(m_hWnd);
 }
 
 /*
@@ -97,7 +90,7 @@ void CValueWnd::Init()
  **/
 void CValueWnd::TopMostWnd()
 {
-	while (true)
+	while (m_is_quit == false)
 	{
 		::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
 
@@ -106,8 +99,12 @@ void CValueWnd::TopMostWnd()
 			//::SendMessage(m_shoukuanHWND, WM_SHOUKUAN_UPDATE_FOCUS, NULL, NULL);
 		}
 
-		Sleep(300);
+		Sleep(100);
 	}
+
+	m_nTaskNum--;
+
+	//线程退出
 }
 
 void CValueWnd::RestartWatch()
@@ -115,16 +112,24 @@ void CValueWnd::RestartWatch()
 	std::thread(&CValueWnd::StartWatchWork, this).detach();
 }
 
+void CValueWnd::StopWatch()
+{
+	m_isWatchWork = false;
+
+	while (m_is_xunichuangkou_working || m_is_chuangkou_working || m_is_orc_working)
+	{
+		//等这3个线程全部退出
+		Sleep(100);
+	}
+}
+
 /*
  *根据当前数据库的设置,重启监听
  **/
 void CValueWnd::StartWatchWork()
 {
 	//先暂停已有的监控
-	m_isWatchWork = false;
-
-	//等待2秒,这2秒就是等已有的监控线程自动退出
-	Sleep(2000);
+	StopWatch();
 
 	//然后开始工作
 	m_isWatchWork = true;
@@ -192,6 +197,8 @@ void CValueWnd::ReadXunichuankouValue()
         return;
     }
 
+	m_is_xunichuangkou_working = true;
+
     char a[1024] = { 0 };
 
 	//检查监控模式和波特率,如果变了就关闭掉
@@ -213,10 +220,14 @@ void CValueWnd::ReadXunichuankouValue()
     }
 
     serial.closeComm();
+
+	m_is_xunichuangkou_working = false;
 }
 
 void CValueWnd::WatchWnd()
 {
+	m_is_chuangkou_working = true;
+
 	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");
@@ -292,10 +303,14 @@ void CValueWnd::WatchWnd()
 
         Sleep(200);
     }
+
+	m_is_chuangkou_working = false;
 }
 
 void CValueWnd::StartOcrWork()
 {
+	m_is_orc_working = true;
+
 	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());
@@ -346,6 +361,8 @@ void CValueWnd::StartOcrWork()
 
 		Sleep(200);
 	}
+
+	m_is_orc_working = false;
 }
 
 LRESULT CValueWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -387,13 +404,6 @@ LRESULT CValueWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandl
  **/
 LRESULT CValueWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
-	Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
-
-	UnregisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN);
-
-	//注意这里不能delete,这个对象会delete自己
-	m_push->Stop();
-
     bHandled = FALSE;
     return 0;
 }
@@ -889,8 +899,6 @@ void CValueWnd::ShowSystemSetting()
 		pSystemSettingFrame->CenterWindow();
 		UINT ret = pSystemSettingFrame->ShowModal();
 
-		m_is_show_setting = false;
-
 		if (ret == IDOK)
 		{
 
@@ -899,6 +907,23 @@ void CValueWnd::ShowSystemSetting()
 		{
 
 		}
+
+		if (pSystemSettingFrame->m_is_logout)
+		{
+			//这个表示是通过退出登录关闭的
+
+			delete pSystemSettingFrame;
+
+			Logout();
+
+			int a = 1;
+		}
+		else
+		{
+			delete pSystemSettingFrame;
+
+			m_is_show_setting = false;
+		}
 	}
 }
 
@@ -1012,6 +1037,66 @@ void CValueWnd::ShowJiaoban()
 	}
 }
 
+void CValueWnd::Logout()
+{
+	//先做一些清理工作
+
+	m_is_quit = true;
+
+	//取消注册的快捷键
+	UnregisterHotKey(m_hWnd, WM_MYHOTKEY_SHOUKUAN);
+
+	//删除右下角的托盘
+	Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
+
+	//注意这里不能delete,这个对象会delete自己
+	m_push->Stop();
+	delete m_push;
+
+	pMenu->Close();
+	delete pMenu;
+
+	pDingweiWnd->Close();
+	delete pDingweiWnd;
+
+	pDingweiInfoWnd->Close();
+	delete pDingweiInfoWnd;
+
+	pOcrWnd->Close();
+	delete pOcrWnd;
+
+	//注销Hook
+	UninstallHook();
+
+	//暂停数据监控
+	StopWatch();
+
+	CSetting::SetParam("setting_is_auto_login", "0", true);
+	CLoginWnd* pLogin = new CLoginWnd();
+
+	if (pLogin == NULL)
+	{
+		return;
+	}
+
+	//设置模式
+	pLogin->Create(NULL, _T("智铺子收银插件登录"), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW, 0, 0, 0, 0, NULL);
+	pLogin->SetIcon(IDI_ICON_DUILIB);
+	pLogin->CenterWindow();
+
+	::ShowWindow(*pLogin, SW_SHOWNORMAL);
+
+	Close();
+
+	int  a = 1;
+}
+
+void CValueWnd::QuitApp()
+{
+	//直接退出整个程序
+	PostQuitMessage(0);
+}
+
 void CValueWnd::UpdateKexian(const char* data, int length)
 {
     std::string new_data = data;
@@ -1347,6 +1432,20 @@ bool CValueWnd::UpdateRegisterHotKey()
 	return nRet;
 }
 
+//全局监听键盘输入
+void CValueWnd::RegKeyboardRawInput()
+{
+	RAWINPUTDEVICE rawInputDevice[1];
+	rawInputDevice[0].usUsagePage = 0x01;//设备类
+	rawInputDevice[0].usUsage = 0x06;//设备类内的具体设备
+	rawInputDevice[0].dwFlags = RIDEV_INPUTSINK;//意味着即使窗口失去焦点位置,仍然会一直接收输入消息
+	rawInputDevice[0].hwndTarget = m_hWnd;
+	if (RegisterRawInputDevices(rawInputDevice, 1, sizeof(rawInputDevice[0])) == FALSE)
+	{
+		printf("RegisterRawInputDevices failed");
+	}
+}
+
 void CValueWnd::PrintTest()
 {
 	m_push->AddPrinter("", 3);

+ 20 - 1
zhipuzi_pay_plugin/wnd/CValueWnd.h

@@ -34,7 +34,7 @@ public:
 
 	void OnFinalMessage(HWND /*hWnd*/)
 	{
-		//m_pm.RemovePreMessageFilter(this);
+		m_pm.RemovePreMessageFilter(this);
 		delete this;
 	};
 
@@ -95,12 +95,18 @@ public:
 	//显示交班页面
 	void ShowJiaoban();
 
+	void Logout();
+
+	void QuitApp();
+
 	void Init();
 
 	void TopMostWnd();
 
 	void RestartWatch();
 
+	void StopWatch();
+
 	void StartWatchWork();
 
 	void ReadXunichuankouValue();
@@ -122,6 +128,8 @@ public:
 	tesseract::TessBaseAPI& GetTess();
 
 	bool UpdateRegisterHotKey();
+
+	void RegKeyboardRawInput();
 	
 	//打印测试小票
 	void PrintTest();
@@ -201,5 +209,16 @@ private:
 	clock_t m_last_catch_clock;
 
 	std::string m_catch_string;
+
+	//退出清理相关的
+	bool m_is_quit = false;
+
+	//这个表示有多少准备工作要做,或者说退出前有多少东西要清理
+	int m_nTaskNum = 0;
+
+	//表示各个监控的状态
+	bool m_is_xunichuangkou_working = false;
+	bool m_is_chuangkou_working = false;
+	bool m_is_orc_working = false;
 };
 

+ 1 - 0
zhipuzi_pay_plugin/zhipuzi_pay_plugin.cpp

@@ -42,6 +42,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
     pLogin->Create(NULL, _T("智铺子收银插件登录"), UI_WNDSTYLE_DIALOG, WS_EX_TOOLWINDOW, 0, 0, 0, 0, NULL);
     pLogin->SetIcon(IDI_ICON_DUILIB);
     pLogin->CenterWindow();
+
     pLogin->ShowModal();
 
     CPaintManagerUI::MessageLoop();