张洋 4 gadi atpakaļ
vecāks
revīzija
c949e34fc7

BIN
bin/Win32/Debug/zhipuzi_pos_windows/skin/eleme_icon.png


BIN
bin/Win32/Debug/zhipuzi_pos_windows/skin/meituan_icon.png


BIN
bin/Win32/Debug/zhipuzi_pos_windows/skin/zhipuzi_waimai_icon.png


+ 1 - 1
zhipuzi_pos_windows/CAppEnv.cpp

@@ -2,7 +2,7 @@
 #include "CAppEnv.h"
 
 #include "print/CPosPrinterQueue.h"
-#include "tool/CChengzhongWorker.h"
+#include "worker/CChengzhongWorker.h"
 #include "worker/CMessagePushWorker.h"
 #include "worker/CCommonWorker.h"
 #include "worker/CVoiceWorker.h"

+ 1 - 1
zhipuzi_pos_windows/page/CSettingPageUI.cpp

@@ -5,7 +5,7 @@
 
 #include "../print/CPosPrinter.h"
 #include "../helper/CComHelper.h"
-#include "../tool/CChengzhongWorker.h"
+#include "../worker/CChengzhongWorker.h"
 
 #include <boost/array.hpp>
 

+ 1 - 1
zhipuzi_pos_windows/wnd/CChengzhongWnd.cpp

@@ -1,7 +1,7 @@
 #include "../pch/pch.h"
 #include "CChengzhongWnd.h"
 
-#include "../tool/CChengzhongWorker.h"
+#include "../worker/CChengzhongWorker.h"
 
 LRESULT CChengzhongWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {

+ 14 - 5
zhipuzi_pos_windows/wnd/CMainWnd.cpp

@@ -225,7 +225,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         }
         else
         {
-            PostQuitMessage(0);
+			QuitApp();
         }
 
         return;
@@ -254,8 +254,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
 
     if(name == _T("quitbtn"))
     {
-        /*Close()*/
-		PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
+		QuitApp();
     }
 	else
 	{
@@ -452,7 +451,8 @@ LRESULT CMainWnd::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
     // 有时会在收到WM_NCDESTROY后收到wParam为SC_CLOSE的WM_SYSCOMMAND
     if(wParam == SC_CLOSE)
     {
-        ::PostQuitMessage(0L);
+		QuitApp();
+
         bHandled = TRUE;
         return 0;
     }
@@ -889,6 +889,7 @@ void CMainWnd::AddTrayIcon()
     Shell_NotifyIcon(NIM_ADD, &m_trayIcon);
     ShowWindow(SW_HIDE);
 }
+
 LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
 {
     //如果在图标中单击左键则还原
@@ -924,8 +925,9 @@ LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan
         {
             m_trayIcon.hIcon = NULL;
             Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
+
             //退出程序
-            ::PostQuitMessage(0);
+			QuitApp();
         }
     }
 
@@ -1081,4 +1083,11 @@ void CMainWnd::DestoryPages()
 	{
 		delete it->second;
 	}
+}
+
+void CMainWnd::QuitApp()
+{
+	this->End();
+
+	PostQuitMessage(0);
 }

+ 3 - 2
zhipuzi_pos_windows/wnd/CMainWnd.h

@@ -27,8 +27,6 @@ public:
 		DIANNEIINFO, //店内订单详情
 	};
 
-    CMainWnd() { };
-
     LPCTSTR GetWindowClassName() const
     {
         return _T("UIMainFrame");
@@ -116,6 +114,9 @@ private:
 
 	void DestoryPages();
 
+	//退出应用时调用
+	void QuitApp();
+
 public:
     CPaintManagerUI m_pm;
 

zhipuzi_pos_windows/tool/CChengzhongWorker.cpp → zhipuzi_pos_windows/worker/CChengzhongWorker.cpp


zhipuzi_pos_windows/tool/CChengzhongWorker.h → zhipuzi_pos_windows/worker/CChengzhongWorker.h


+ 47 - 3
zhipuzi_pos_windows/worker/CMessagePushWorker.cpp

@@ -27,10 +27,28 @@ void CMessagePushWorker::Stop()
 
 	socket_.close();
 
-	//等到线程完全退出,程序才退出,否则会报错
-	while (m_nStopNum < 2)
+	return;
+
+	sleepMutex.lock();
+	if (m_is_sleep == true)
+	{
+		//如果心跳线程正在睡眠,就不等了
+		sleepMutex.unlock();
+
+		while (m_nStopNum < 1)
+		{
+			Sleep(100);
+		}
+	}
+	else
 	{
-		Sleep(100);
+		//如果心跳线程没有睡眠,就等待
+		sleepMutex.unlock();
+
+		while (m_nStopNum < 2)
+		{
+			Sleep(100);
+		}
 	}
 }
 
@@ -120,8 +138,21 @@ void CMessagePushWorker::KeepAlive()
 				socket_.close();
 
 				//30秒后再重试
+				if (m_is_work == false)
+				{
+					continue;
+				}
+
+				sleepMutex.lock();
+				m_is_sleep = true;
+				sleepMutex.unlock();
+
 				CSystem::my_sleep(30);
 
+				sleepMutex.lock();
+				m_is_sleep = false;
+				sleepMutex.unlock();
+
 				continue;
 			}
 		}
@@ -129,7 +160,20 @@ void CMessagePushWorker::KeepAlive()
 		//走到这里,说明心跳包发送成功了,socket是连通的
 
 		//休眠30秒钟,之后再发心跳包
+		if (m_is_work == false)
+		{
+			continue;
+		}
+
+		sleepMutex.lock();
+		m_is_sleep = true;
+		sleepMutex.unlock();
+
 		CSystem::my_sleep(30);
+
+		sleepMutex.lock();
+		m_is_sleep = false;
+		sleepMutex.unlock();
 	}
 
 	AddStopNum();

+ 5 - 2
zhipuzi_pos_windows/worker/CMessagePushWorker.h

@@ -31,9 +31,9 @@ class CMessagePushWorker
 public:
 	static CMessagePushWorker* GetInstance()
 	{
-		static CMessagePushWorker instance;
+		CMessagePushWorker* instance = new CMessagePushWorker;
 
-		return &instance;
+		return instance;
 	}
 
 	//开始工作
@@ -74,4 +74,7 @@ private:
 	char data_[max_length];
 
 	HWND m_hwnd;
+
+	bool m_is_sleep;
+	std::mutex sleepMutex;
 };

+ 3 - 2
zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj

@@ -238,7 +238,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClInclude Include="control\CDianneiOrderItemUI.h" />
     <ClInclude Include="page\CDianneiOrderInfoPageUI.h" />
     <ClInclude Include="page\CDianneiOrderListPageUI.h" />
-    <ClInclude Include="tool\CChengzhongWorker.h" />
+    <ClInclude Include="worker\CChengzhongWorker.h" />
     <ClInclude Include="print\CPosPrinter.h" />
     <ClInclude Include="print\CPosPrinterQueue.h" />
     <ClInclude Include="wnd\CGuadanWnd.h" />
@@ -321,7 +321,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <ClCompile Include="control\CDianneiOrderItemUI.cpp" />
     <ClCompile Include="page\CDianneiOrderInfoPageUI.cpp" />
     <ClCompile Include="page\CDianneiOrderListPageUI.cpp" />
-    <ClCompile Include="tool\CChengzhongWorker.cpp" />
+    <ClCompile Include="worker\CChengzhongWorker.cpp" />
     <ClCompile Include="print\CPosPrinter.cpp" />
     <ClCompile Include="print\CPosPrinterQueue.cpp" />
     <ClCompile Include="wnd\CGuadanWnd.cpp" />
@@ -391,6 +391,7 @@ copy $(ProjectDir)conf\ $(SolutionDir)bin\$(Platform)\$(Configuration)\conf\</Co
     <Image Include="resource\zhipuzi.ico" />
   </ItemGroup>
   <ItemGroup>
+    <None Include="resource\skin.zip" />
     <None Include="resource\zhipuzi_pos_windows.aps" />
   </ItemGroup>
   <ItemGroup>

+ 7 - 6
zhipuzi_pos_windows/zhipuzi_pos_windows.vcxproj.filters

@@ -216,9 +216,6 @@
     <ClInclude Include="print\CPosPrinter.h">
       <Filter>头文件</Filter>
     </ClInclude>
-    <ClInclude Include="tool\CChengzhongWorker.h">
-      <Filter>头文件</Filter>
-    </ClInclude>
     <ClInclude Include="page\CDianneiOrderInfoPageUI.h">
       <Filter>头文件</Filter>
     </ClInclude>
@@ -258,6 +255,9 @@
     <ClInclude Include="worker\CMessagePushWorker.h">
       <Filter>头文件</Filter>
     </ClInclude>
+    <ClInclude Include="worker\CChengzhongWorker.h">
+      <Filter>头文件</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="pch\pch.cpp">
@@ -440,9 +440,6 @@
     <ClCompile Include="print\CPosPrinter.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
-    <ClCompile Include="tool\CChengzhongWorker.cpp">
-      <Filter>源文件</Filter>
-    </ClCompile>
     <ClCompile Include="page\CDianneiOrderInfoPageUI.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
@@ -479,6 +476,9 @@
     <ClCompile Include="worker\CMessagePushWorker.cpp">
       <Filter>源文件</Filter>
     </ClCompile>
+    <ClCompile Include="worker\CChengzhongWorker.cpp">
+      <Filter>源文件</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <Image Include="resource\zhipuzi.ico">
@@ -492,6 +492,7 @@
   </ItemGroup>
   <ItemGroup>
     <None Include="resource\zhipuzi_pos_windows.aps" />
+    <None Include="resource\skin.zip" />
   </ItemGroup>
   <ItemGroup>
     <Text Include="helper\readme.txt" />