Bläddra i källkod

托盘的处理好了

zhangyang 6 år sedan
förälder
incheckning
915bcf040d

BIN
bin/Win32/Debug/zhipuzi_pos_windows/db/pos.db


+ 1 - 1
bin/Win32/Debug/zhipuzi_pos_windows/skin/setting.xml

@@ -83,7 +83,7 @@
 						<CheckBox name="setting_is_auto_login" width="72" height="45" normalimage="file='switchbutton.png' source='0,0,143,91'" selectedimage="file='switchbutton.png' source='0,182,143,273'"/>
 					</HorizontalLayout>
 					<HorizontalLayout height="44">
-						<Label text="关闭主面板时,最小化到任务栏" width="260" />
+						<Label text="点击关闭时,最小化到系统托盘" width="260" />
 						<CheckBox name="setting_is_close_min" width="72" height="45" normalimage="file='switchbutton.png' source='0,0,143,91'" selectedimage="file='switchbutton.png' source='0,182,143,273'"/>
 					</HorizontalLayout>
 				</VerticalLayout>

BIN
bin/Win32/Debug/zhipuzi_pos_windows/zhipuzi_pos_windows.exe


+ 65 - 14
lewaimai_dispatch/helper/CSystem.h

@@ -3,24 +3,75 @@
 class CSystem
 {
 public:
-	CSystem();
-	~CSystem();
+    CSystem();
+    ~CSystem();
 
-	static int get_CPU_core_num();
+    static int get_CPU_core_num();
 
-	//程序休眠X秒
-	static void my_sleep(int second);
+    //程序休眠X秒
+    static void my_sleep(int second);
 
-	static std::wstring GetProgramDir()
-	{
-		wchar_t exeFullPath[MAX_PATH]; // Full path
-		std::wstring strPath = L"";
+    static std::wstring GetProgramDir()
+    {
+        wchar_t exeFullPath[MAX_PATH]; // Full path
+        std::wstring strPath = L"";
 
-		GetModuleFileName(NULL, exeFullPath, MAX_PATH);
-		strPath = (wstring)exeFullPath;    // Get full path of the file
+        GetModuleFileName(NULL, exeFullPath, MAX_PATH);
+        strPath = (wstring)exeFullPath;    // Get full path of the file
 
-		int pos = strPath.find_last_of('\\', strPath.length());
-		return strPath.substr(0, pos);  // Return the directory without the file name
-	}
+        int pos = strPath.find_last_of('\\', strPath.length());
+        return strPath.substr(0, pos);  // Return the directory without the file name
+    }
+
+    // 程序开机自动启动
+    static void autostart()
+    {
+        HKEY hKey;
+        wstring strRegPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
+
+        //1、找到系统的启动项
+        if(RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath.c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)  ///打开启动项
+        {
+            //2、得到本程序自身的全路径
+            TCHAR strExeFullDir[MAX_PATH];
+            GetModuleFileName(NULL, strExeFullDir, MAX_PATH);
+
+            //3、判断注册表项是否已经存在
+            TCHAR strDir[MAX_PATH] = {};
+            DWORD nLength = MAX_PATH;
+            long result = RegGetValue(hKey, nullptr, L"智铺子收银软件", RRF_RT_REG_SZ, 0, strDir, &nLength);
+
+            //4、已经存在
+            if(result != ERROR_SUCCESS || _tcscmp(strExeFullDir, strDir) != 0)
+            {
+                //5、添加一个子Key,并设置值,"GISRestart"是应用程序名字(不加后缀.exe)
+                RegSetValueEx(hKey, L"智铺子收银软件", 0, REG_SZ, (LPBYTE)strExeFullDir, (lstrlen(strExeFullDir) + 1) * sizeof(TCHAR));
+
+                //6、关闭注册表
+                RegCloseKey(hKey);
+            }
+        }
+        else
+        {
+            cout << "系统参数错误, 不能随系统启动";
+        }
+    }
+
+    // 取消开机自动启动
+    static void cancelAutoStart()
+    {
+        HKEY hKey;
+        wstring strRegPath = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";
+
+        //1、找到系统的启动项
+        if(RegOpenKeyEx(HKEY_CURRENT_USER, strRegPath.c_str(), 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS)
+        {
+            //2、删除值
+            RegDeleteValue(hKey, L"智铺子收银软件");
+
+            //3、关闭注册表
+            RegCloseKey(hKey);
+        }
+    }
 };
 

BIN
lewaimai_dispatch/resource/zhipuzi_pos_windows.aps


+ 240 - 183
lewaimai_dispatch/wnd/CMainWnd.cpp

@@ -8,6 +8,8 @@
 
 #include "../tool/CSetting.h"
 
+
+
 void CMainWnd::Init()
 {
     m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
@@ -15,11 +17,11 @@ void CMainWnd::Init()
     m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
     m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
 
-	OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
-	orderlist->Refresh();
+    OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
+    orderlist->Refresh();
 
-	//初始化设置中心的状态
-	InitSettingStatus();
+    //初始化设置中心的状态
+    InitSettingStatus();
 }
 
 LRESULT CMainWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
@@ -78,22 +80,14 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
 {
     if(msg.pSender == m_pCloseBtn)
     {
-        COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
-
-        if(pControl && pControl->IsSelected() == false)
-        {
-            CControlUI* pFadeControl = m_pm.FindControl(_T("fadeEffect"));
-
-            if(pFadeControl)
-            {
-                pFadeControl->SetVisible(true);
-            }
-        }
-
-        else
-        {
-            /*Close()*/PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
-        }
+		if (CSetting::GetParam("setting_is_close_min") == "1")
+		{
+			AddTrayIcon();
+		}
+		else
+		{
+			PostQuitMessage(0); 
+		}
 
         return;
     }
@@ -134,7 +128,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
 
         CPosPrinter printer;
         printer.PrintWaimaiOrderShouyin(order);
-		//printer.PrintWaimaiOrderChufang(order);
+        //printer.PrintWaimaiOrderChufang(order);
     }
 
     else if(name == _T("waimai_order_list_confirme"))
@@ -287,7 +281,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
 
         CPosPrinter printer;
         printer.PrintWaimaiOrderShouyin(order_info_page->m_order);
-		//printer.PrintWaimaiOrderChufang(order_info_page->m_order);
+        //printer.PrintWaimaiOrderChufang(order_info_page->m_order);
     }
 
     else if(name == _T("waimai_order_info_page_confirme"))
@@ -543,7 +537,7 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
                     pFenlei->SetText(L"否");
                 }
 
-				pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
+                pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
 
                 pPrinterList->Add(pEle);
             }
@@ -557,11 +551,15 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
         if(box->IsSelected())
         {
             CSetting::SetParam("setting_is_auto_start", "0");
+
+            CSystem::cancelAutoStart();
         }
 
         else
         {
             CSetting::SetParam("setting_is_auto_start", "1");
+
+            CSystem::autostart();
         }
     }
 
@@ -594,107 +592,107 @@ void CMainWnd::HandleClickMsg(TNotifyUI& msg)
             CSetting::SetParam("setting_is_close_min", "1");
         }
     }
-	else if (name == _T("setting_chufang_printer_item_update_btn"))
-	{
-		CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
+    else if(name == _T("setting_chufang_printer_item_update_btn"))
+    {
+        CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
 
-		CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
-		wstring date = pEle->GetCustomAttribute(L"date");
+        CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
+        wstring date = pEle->GetCustomAttribute(L"date");
 
-		CChufangSettingWnd* pChufangFrame = new CChufangSettingWnd(2);
-		pChufangFrame->SetPrinterDate(CLewaimaiString::UnicodeToUTF8(date));
+        CChufangSettingWnd* pChufangFrame = new CChufangSettingWnd(2);
+        pChufangFrame->SetPrinterDate(CLewaimaiString::UnicodeToUTF8(date));
 
-		if (pChufangFrame != NULL)
-		{
-			pChufangFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
-			pChufangFrame->SetIcon(IDI_ICON_DUILIB);
-			pChufangFrame->CenterWindow();
-			UINT ret = pChufangFrame->ShowModal();
-
-			if (ret == IDOK)
-			{
-				//这个时候是点击保存返回了,厨房打印机的数据已经建立好了,这个时候刷新表格的显示
-				CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
-
-				ChufangPrinter newPrinter = CSetting::GetChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
-
-				CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
-				pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
-
-				CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
-				pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
-
-				CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
-
-				if (newPrinter.guige == "58")
-				{
-					pGuige->SetText(L"58mm");
-				}
-				else
-				{
-					pGuige->SetText(L"80mm");
-				}
-
-				CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
-
-				if (newPrinter.fendan == "1")
-				{
-					pFendan->SetText(L"是");
-				}
-				else
-				{
-					pFendan->SetText(L"否");
-				}
-
-				CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
-
-				if (newPrinter.fenlei == "1")
-				{
-					pFenlei->SetText(L"是");
-				}
-				else
-				{
-					pFenlei->SetText(L"否");
-				}
-
-				std::string foodtypeNames = "";
-
-				std::string foodtype_ids = newPrinter.fenlei_ids;
-				std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
-				for (std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
-				{
-					std::string name = CSetting::getFoodtypeName((*it));
-					std::wstring ws_name = CLewaimaiString::UTF8ToUnicode(name);
-					if (name == "zhipuzi_not_found_xxx")
-					{
-						//这种情况是以前保存的分类后来被删掉了
-					}
-					else
-					{
-						foodtypeNames += name + "  ";
-					}
-				}
-
-				foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
-				std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
-
-				CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
-				pFenleiIds->SetText(ws_foodtypeNames.c_str());
-			}
-		}
-	}
-	else if (name == _T("setting_chufang_printer_item_delete_btn"))
-	{
-		CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
+        if(pChufangFrame != NULL)
+        {
+            pChufangFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
+            pChufangFrame->SetIcon(IDI_ICON_DUILIB);
+            pChufangFrame->CenterWindow();
+            UINT ret = pChufangFrame->ShowModal();
+
+            if(ret == IDOK)
+            {
+                //这个时候是点击保存返回了,厨房打印机的数据已经建立好了,这个时候刷新表格的显示
+                CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
+
+                ChufangPrinter newPrinter = CSetting::GetChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
+
+                CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
+                pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
+
+                CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
+                pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
+
+                CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
+
+                if(newPrinter.guige == "58")
+                {
+                    pGuige->SetText(L"58mm");
+                }
+                else
+                {
+                    pGuige->SetText(L"80mm");
+                }
 
-		CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
-		wstring date = pEle->GetCustomAttribute(L"date");
+                CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
 
-		//获得了ID,这个时候从内存和数据库中分别删除对应的记录
-		CSetting::DelChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
+                if(newPrinter.fendan == "1")
+                {
+                    pFendan->SetText(L"是");
+                }
+                else
+                {
+                    pFendan->SetText(L"否");
+                }
 
-		pPrinterList->Remove(pEle);
-	}
+                CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
+
+                if(newPrinter.fenlei == "1")
+                {
+                    pFenlei->SetText(L"是");
+                }
+                else
+                {
+                    pFenlei->SetText(L"否");
+                }
+
+                std::string foodtypeNames = "";
+
+                std::string foodtype_ids = newPrinter.fenlei_ids;
+                std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
+                for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
+                {
+                    std::string name = CSetting::getFoodtypeName((*it));
+                    std::wstring ws_name = CLewaimaiString::UTF8ToUnicode(name);
+                    if(name == "zhipuzi_not_found_xxx")
+                    {
+                        //这种情况是以前保存的分类后来被删掉了
+                    }
+                    else
+                    {
+                        foodtypeNames += name + "  ";
+                    }
+                }
+
+                foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
+                std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
+
+                CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
+                pFenleiIds->SetText(ws_foodtypeNames.c_str());
+            }
+        }
+    }
+    else if(name == _T("setting_chufang_printer_item_delete_btn"))
+    {
+        CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
+
+        CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
+        wstring date = pEle->GetCustomAttribute(L"date");
+
+        //获得了ID,这个时候从内存和数据库中分别删除对应的记录
+        CSetting::DelChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
+
+        pPrinterList->Remove(pEle);
+    }
 }
 
 void CMainWnd::HandleSelectChangeMsg(TNotifyUI& msg)
@@ -901,6 +899,9 @@ LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
     case WM_SYSCOMMAND:
         lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
         break;
+	case  WM_SHOWTASK:
+		lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
+		break;
 
     default:
         bHandled = FALSE;
@@ -1094,6 +1095,62 @@ LRESULT CMainWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHa
     return HTCLIENT;
 }
 
+void CMainWnd::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);
+    ShowWindow(SW_HIDE);
+}
+LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
+{
+    //如果在图标中单击左键则还原
+    if(lParam == WM_LBUTTONDOWN)
+    {
+        //删除托盘图标
+        Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
+        //显示主窗口
+        ShowWindow(SW_SHOWNORMAL);
+		//窗口最大化
+		SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
+    }
+    //如果在图标中单击右键则弹出声明式菜单
+    if(lParam == WM_RBUTTONDOWN)
+    {
+        //获取鼠标坐标
+        POINT pt;
+        GetCursorPos(&pt);
+        //右击后点别地可以清除“右击出来的菜单”
+        SetForegroundWindow(m_hWnd);
+        //托盘菜单    win32程序使用的是HMENU,如果是MFC程序可以使用CMenu
+        HMENU hMenu;
+        //生成托盘菜单
+        hMenu = CreatePopupMenu();
+        //添加菜单,关键在于设置的一个标识符  WM_ONCLOSE 点击后会用到
+        AppendMenu(hMenu, MF_STRING, WM_ONCLOSE, _T("退出"));
+        //弹出菜单,并把用户所选菜单项的标识符返回
+        int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, NULL, m_hWnd, NULL);
+        //如果标识符是WM_ONCLOSE则关闭
+        if(cmd == WM_ONCLOSE)
+        {
+            m_trayIcon.hIcon = NULL;
+            Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
+            //退出程序
+            ::PostQuitMessage(0);
+        }
+    }
+
+    bHandled = true;
+    return 0;
+}
+
 void CMainWnd::InitSettingStatus()
 {
     CCheckBoxUI* box = NULL;
@@ -1243,51 +1300,51 @@ void CMainWnd::InitSettingStatus()
     //这里开始,初始化厨房打印机的设置
     CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
 
-	//获取当前店铺的商品分类信息,用于设置厨房打印机的分类打印
-	std::map<string, string> params;
-	std::string response;
+    //获取当前店铺的商品分类信息,用于设置厨房打印机的分类打印
+    std::map<string, string> params;
+    std::string response;
 
-	std::string url = "/goodstype/getgoodstypelist";
+    std::string url = "/goodstype/getgoodstypelist";
 
-	CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
+    CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
 
-	rapidjson::Document document;
-	document.Parse(response.c_str());
+    rapidjson::Document document;
+    document.Parse(response.c_str());
 
-	if (document.HasParseError())
-	{
-		LOG_INFO("parse response error!");
-		return;
-	}
+    if(document.HasParseError())
+    {
+        LOG_INFO("parse response error!");
+        return;
+    }
 
-	if (!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
-	{
-		LOG_INFO("json error!");
-		return;
-	}
+    if(!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
+    {
+        LOG_INFO("json error!");
+        return;
+    }
 
-	rapidjson::Value& v_errcode = document["errcode"];
-	int errcode = v_errcode.GetInt();
-	if (errcode != 0)
-	{
-		LOG_INFO("response failed! message:" << document["errmsg"].GetString());
-		return;
-	}
+    rapidjson::Value& v_errcode = document["errcode"];
+    int errcode = v_errcode.GetInt();
+    if(errcode != 0)
+    {
+        LOG_INFO("response failed! message:" << document["errmsg"].GetString());
+        return;
+    }
 
-	//获得数据成功,把分类信息保存起来
-	rapidjson::Value& data = document["data"];
+    //获得数据成功,把分类信息保存起来
+    rapidjson::Value& data = document["data"];
 
-	rapidjson::Value& v_rows = data["goods_types"];
+    rapidjson::Value& v_rows = data["goods_types"];
 
-	for (rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
-	{
-		rapidjson::Value& v_row_i = v_rows[i];
+    for(rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
+    {
+        rapidjson::Value& v_row_i = v_rows[i];
 
-		std::string type_id = v_row_i["type_id"].GetString();
-		std::string name = v_row_i["name"].GetString();
+        std::string type_id = v_row_i["type_id"].GetString();
+        std::string name = v_row_i["name"].GetString();
 
-		CSetting::AddFoodtype(name, type_id);
-	}
+        CSetting::AddFoodtype(name, type_id);
+    }
 
     //获取厨房打印机的集合
     std::vector<ChufangPrinter> printers = CSetting::getChufangPrints();
@@ -1338,44 +1395,44 @@ void CMainWnd::InitSettingStatus()
             pFenlei->SetText(L"否");
         }
 
-		std::string foodtypeNames = "";
+        std::string foodtypeNames = "";
 
-		std::string foodtype_ids = newPrinter.fenlei_ids;
+        std::string foodtype_ids = newPrinter.fenlei_ids;
 
-		//这个是删除掉不存在的type_id之后的
-		std::string new_foodtype_ids = "";
+        //这个是删除掉不存在的type_id之后的
+        std::string new_foodtype_ids = "";
 
-		std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
-		for (std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
-		{
-			std::string name = CSetting::getFoodtypeName((*it));
-			if (name == "zhipuzi_not_found_xxx")
-			{
-				//这种情况是以前保存的分类后来被删掉了
-			}
-			else
-			{
-				foodtypeNames += name + "  ";
-
-				new_foodtype_ids += (*it) + ",";
-			}
-		}
+        std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
+        for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
+        {
+            std::string name = CSetting::getFoodtypeName((*it));
+            if(name == "zhipuzi_not_found_xxx")
+            {
+                //这种情况是以前保存的分类后来被删掉了
+            }
+            else
+            {
+                foodtypeNames += name + "  ";
 
-		//删掉不存在的type_id,更新内存和数据库
-		new_foodtype_ids = new_foodtype_ids.substr(0, new_foodtype_ids.length() - 1);
-		if (new_foodtype_ids.compare(foodtype_ids) != 0)
-		{
-			CSetting::UpdateChufangPrinter(newPrinter.date, newPrinter.name, newPrinter.ip, newPrinter.guige, newPrinter.fendan, newPrinter.fenlei, new_foodtype_ids, true);
-		}
+                new_foodtype_ids += (*it) + ",";
+            }
+        }
+
+        //删掉不存在的type_id,更新内存和数据库
+        new_foodtype_ids = new_foodtype_ids.substr(0, new_foodtype_ids.length() - 1);
+        if(new_foodtype_ids.compare(foodtype_ids) != 0)
+        {
+            CSetting::UpdateChufangPrinter(newPrinter.date, newPrinter.name, newPrinter.ip, newPrinter.guige, newPrinter.fendan, newPrinter.fenlei, new_foodtype_ids, true);
+        }
 
-		foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);		
-		std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
+        foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
+        std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
 
-		CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
-		pFenleiIds->SetText(ws_foodtypeNames.c_str());
+        CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
+        pFenleiIds->SetText(ws_foodtypeNames.c_str());
 
-		//设置标记属性,用于修改时候匹配
-		pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
+        //设置标记属性,用于修改时候匹配
+        pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
 
         pPrinterList->Add(pEle);
     }

+ 15 - 0
lewaimai_dispatch/wnd/CMainWnd.h

@@ -6,6 +6,11 @@
 #include "../order/CWaimaiOrder.h"
 #include "../tool/CPosPrinter.h"
 
+#include <ShellAPI.h>
+
+#define WM_SHOWTASK 10001
+#define WM_ONCLOSE 10002
+
 class CMainWnd : public CWindowWnd, public INotifyUI
 {
 public:
@@ -86,6 +91,13 @@ public:
 
 	LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
 
+	
+	//添加托盘图标(初始化)
+	void AddTrayIcon();
+
+	//处理托盘图标上的事件
+	LRESULT OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+
 public:
     CPaintManagerUI m_pm;
 
@@ -94,4 +106,7 @@ private:
     CButtonUI* m_pMaxBtn;
     CButtonUI* m_pRestoreBtn;
     CButtonUI* m_pMinBtn;
+
+	//定义托盘图标对象
+	NOTIFYICONDATA m_trayIcon;
 };