CMainWnd.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. #include "../pch/pch.h"
  2. #include "CMainWnd.h"
  3. #include "CLoginWnd.h"
  4. #include "../control/ControlEx.h"
  5. #include "../page/CWaimaiOrderInfoPageUI.h"
  6. #include "../network/CMessagePush.h"
  7. #include <urlmon.h>
  8. void CMainWnd::Init()
  9. {
  10. m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
  11. m_pMaxBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("maxbtn")));
  12. m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
  13. m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
  14. //默认选择点单页面
  15. this->SwitchPage(DIANDAN);
  16. //登录成功,启动消息和任务处理
  17. m_push = new CMessagePush(m_hWnd);
  18. m_push->Start();
  19. //启动一个线程,开始同步商品图片
  20. std::thread(&CMainWnd::UpdateFoodImage, this).detach();
  21. }
  22. void CMainWnd::UpdateFoodImage()
  23. {
  24. //先判断并创建临时目录
  25. string folderPath = CLewaimaiString::UnicodeToANSI(CSystem::GetProgramDir()) + "\\tmp\\image";
  26. std::wstring ws_folderPath = CLewaimaiString::ANSIToUnicode(folderPath);
  27. if (!CSystem::IsDirExist(ws_folderPath))
  28. {
  29. LOG_INFO("folderPath:" << folderPath.c_str() << ",没有找到对应的目录,即将创建");
  30. CSystem::CreateMultiLevel(folderPath);
  31. }
  32. CSqlite3 sqlite;
  33. std::vector<CFood> foodlist = sqlite.GetFoodByTypeid("0", true);
  34. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  35. {
  36. CFood food = *it;
  37. if (food.goods_img.size() == 0)
  38. {
  39. //没有图片,直接跳过
  40. continue;
  41. }
  42. std::wstring ws_goods_img = food.getImageUrl();
  43. ws_goods_img += L"!max200"; //下载小图
  44. wstring imagePath = food.getImageTmpPath();
  45. if (CSystem::IsFileExist(imagePath))
  46. {
  47. //如果图片文件已经存在,直接跳过
  48. continue;
  49. }
  50. //图片还不存在,开始下载
  51. if (URLDownloadToFile(NULL, ws_goods_img.c_str(), imagePath.c_str(), 0, NULL) == S_OK)
  52. {
  53. //图片下载成功了,发个消息,更新图片
  54. }
  55. else
  56. {
  57. LOG_INFO("URLDownloadToFile Fail,Error"<<GetLastError());
  58. }
  59. }
  60. //再处理商品套餐的图片
  61. std::vector<CFoodpackage> foodpackagelist = sqlite.GetFoodpackages(true);
  62. for (std::vector<CFoodpackage>::iterator it = foodpackagelist.begin(); it != foodpackagelist.end(); it++)
  63. {
  64. CFoodpackage food = *it;
  65. if (food.goods_img.size() == 0)
  66. {
  67. //没有图片,直接跳过
  68. continue;
  69. }
  70. std::wstring ws_goods_img = food.getImageUrl();
  71. ws_goods_img += L"!max200"; //下载小图
  72. wstring imagePath = food.getImageTmpPath();
  73. if (CSystem::IsFileExist(imagePath))
  74. {
  75. //如果图片文件已经存在,直接跳过
  76. continue;
  77. }
  78. //图片还不存在,开始下载
  79. if (URLDownloadToFile(NULL, ws_goods_img.c_str(), imagePath.c_str(), 0, NULL) == S_OK)
  80. {
  81. //图片下载成功了,发个消息,更新图片
  82. }
  83. else
  84. {
  85. LOG_INFO("URLDownloadToFile Fail,Error" << GetLastError());
  86. }
  87. }
  88. }
  89. void CMainWnd::SwitchPage(MainPageName name)
  90. {
  91. if (m_curPageName == name)
  92. {
  93. return;
  94. }
  95. //先删除现在的子对象
  96. CContainerUI* pMainContentLayout = static_cast<CContainerUI*>(m_pm.FindControl(_T("main_content_layout")));
  97. pMainContentLayout->RemoveAll();
  98. //再创建一个对象
  99. CDialogBuilder builder;
  100. CDialogBuilderCallbackEx cb;
  101. CBasePageUI* pChildContainer = NULL;
  102. //注意事项:所有的子页面中的option不能带有selected="true"属性,如果带有这个属性,在下面的Create调用的时候就直接会生成一个selectchanged事件,但是这个时候
  103. //页面才刚刚Create,还没加入到窗口中,相关的变量对应关系也还没设置成功,会导致事件处理对象出现问题
  104. if (name == DIANDAN)
  105. {
  106. pChildContainer = static_cast<CBasePageUI*>(builder.Create(_T("diandan_page.xml"), (UINT)0, &cb, &m_pm));
  107. }
  108. else if (name == DINGDAN)
  109. {
  110. pChildContainer = static_cast<CBasePageUI*>(builder.Create(_T("waimaiorder_list_page.xml"), (UINT)0, &cb, &m_pm));
  111. }
  112. else if (name == SHEZHI)
  113. {
  114. pChildContainer = static_cast<CBasePageUI*>(builder.Create(_T("setting_page.xml"), (UINT)0, &cb, &m_pm));
  115. }
  116. else if (name == WAIMAIINFO)
  117. {
  118. pChildContainer = static_cast<CBasePageUI*>(builder.Create(_T("waimaiorder_info_page.xml"), (UINT)0, &cb, &m_pm));
  119. CWaimaiOrderInfoPageUI* pInfoPage = static_cast<CWaimaiOrderInfoPageUI*>(pChildContainer);
  120. pInfoPage->m_order_id = m_infopage_waimaiorder_id;
  121. pInfoPage->m_order_no = m_infopage_waimaiorder_no;
  122. }
  123. pChildContainer->SetMainWnd(this);
  124. pMainContentLayout->Add(pChildContainer);
  125. m_curPageName = name;
  126. m_curPageUI = pChildContainer;
  127. pChildContainer->InitShow();
  128. }
  129. LRESULT CMainWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  130. {
  131. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  132. styleValue &= ~WS_CAPTION;
  133. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  134. m_pm.Init(m_hWnd);
  135. CDialogBuilder builder;
  136. CDialogBuilderCallbackEx cb;
  137. CControlUI* pRoot = builder.Create(_T("main.xml"), (UINT)0, &cb, &m_pm);
  138. ASSERT(pRoot && "Failed to parse XML");
  139. m_pm.AttachDialog(pRoot);
  140. m_pm.AddNotifier(this);
  141. Init();
  142. return 0;
  143. }
  144. void CMainWnd::Notify(TNotifyUI& msg)
  145. {
  146. if(msg.sType == _T("windowinit"))
  147. {
  148. }
  149. else if(msg.sType == _T("click"))
  150. {
  151. HandleClickMsg(msg);
  152. }
  153. else if(msg.sType == _T("selectchanged"))
  154. {
  155. HandleSelectChangeMsg(msg);
  156. }
  157. else if(msg.sType == _T("itemclick"))
  158. {
  159. }
  160. else if(msg.sType == _T("itemactivate"))
  161. {
  162. }
  163. else if(msg.sType == _T("itemselect"))
  164. {
  165. HandleItemSelectMsg(msg);
  166. }
  167. else if (msg.sType == _T("textchanged"))
  168. {
  169. //编辑框内容改变事件
  170. }
  171. }
  172. void CMainWnd::HandleClickMsg(TNotifyUI& msg)
  173. {
  174. if(msg.pSender == m_pCloseBtn)
  175. {
  176. if(CSetting::GetParam("setting_is_close_min") == "1")
  177. {
  178. AddTrayIcon();
  179. }
  180. else
  181. {
  182. PostQuitMessage(0);
  183. }
  184. return;
  185. }
  186. else if(msg.pSender == m_pMinBtn)
  187. {
  188. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  189. return;
  190. }
  191. else if(msg.pSender == m_pMaxBtn)
  192. {
  193. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  194. return;
  195. }
  196. else if(msg.pSender == m_pRestoreBtn)
  197. {
  198. SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
  199. return;
  200. }
  201. CDuiString name = msg.pSender->GetName();
  202. if(name == _T("quitbtn"))
  203. {
  204. /*Close()*/
  205. PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
  206. }
  207. else
  208. {
  209. this->m_curPageUI->HandleClickMsg(msg);
  210. }
  211. }
  212. /**
  213. * 这个处理Option的切换
  214. */
  215. void CMainWnd::HandleSelectChangeMsg(TNotifyUI& msg)
  216. {
  217. CDuiString name = msg.pSender->GetName();
  218. //先判断主页面的tab
  219. if (name == _T("main_diandan"))
  220. {
  221. this->SwitchPage(DIANDAN);
  222. }
  223. else if(name == _T("main_waimai"))
  224. {
  225. this->SwitchPage(DINGDAN);
  226. }
  227. else if(name == _T("main_setting"))
  228. {
  229. this->SwitchPage(SHEZHI);
  230. }
  231. else
  232. {
  233. //除了主界面固定区域的事件,其他的事件全部分发给子页面
  234. this->m_curPageUI->HandleSelectChangeMsg(msg);
  235. }
  236. }
  237. void CMainWnd::HandleItemSelectMsg(TNotifyUI& msg)
  238. {
  239. this->m_curPageUI->HandleItemSelectMsg(msg);
  240. }
  241. void CMainWnd::HandleTextChangedMsg(TNotifyUI& msg)
  242. {
  243. }
  244. LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  245. {
  246. LRESULT lRes = 0;
  247. BOOL bHandled = TRUE;
  248. switch(uMsg)
  249. {
  250. case WM_CREATE:
  251. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  252. break;
  253. case WM_CLOSE:
  254. lRes = OnClose(uMsg, wParam, lParam, bHandled);
  255. break;
  256. case WM_DESTROY:
  257. lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
  258. break;
  259. case WM_NCACTIVATE:
  260. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  261. break;
  262. case WM_NCCALCSIZE:
  263. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  264. break;
  265. case WM_NCPAINT:
  266. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  267. break;
  268. case WM_NCHITTEST:
  269. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  270. break;
  271. case WM_SIZE:
  272. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  273. break;
  274. case WM_GETMINMAXINFO:
  275. lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled);
  276. break;
  277. case WM_SYSCOMMAND:
  278. lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
  279. break;
  280. case WM_SHOWTASK:
  281. lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
  282. break;
  283. default:
  284. bHandled = FALSE;
  285. }
  286. if(bHandled)
  287. {
  288. return lRes;
  289. }
  290. //走到这里,说明消息还没有处理,应该是自定义的消息
  291. bool ret = this->HandleCustomMessage(uMsg, wParam, lParam);
  292. if (ret)
  293. {
  294. //自定义消息已经处理
  295. return 0;
  296. }
  297. if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  298. {
  299. return lRes;
  300. }
  301. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  302. }
  303. bool CMainWnd::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  304. {
  305. if (uMsg == WM_ORDERLIST_REFRESH)
  306. {
  307. if (m_curPageName != DINGDAN)
  308. {
  309. return true;
  310. }
  311. static_cast<CWaimaiOrderListPageUI*>(this->m_curPageUI)->DoRefresh();
  312. return true;
  313. }
  314. else if (uMsg == WM_LOGIN_AGAIN_OUT)
  315. {
  316. LoginOut(2);
  317. return true;
  318. }
  319. return false;
  320. }
  321. LRESULT CMainWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  322. {
  323. return false;
  324. }
  325. LRESULT CMainWnd::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  326. {
  327. // 有时会在收到WM_NCDESTROY后收到wParam为SC_CLOSE的WM_SYSCOMMAND
  328. if(wParam == SC_CLOSE)
  329. {
  330. ::PostQuitMessage(0L);
  331. bHandled = TRUE;
  332. return 0;
  333. }
  334. BOOL bZoomed = ::IsZoomed(*this);
  335. LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  336. if(::IsZoomed(*this) != bZoomed)
  337. {
  338. if(!bZoomed)
  339. {
  340. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  341. if(pControl)
  342. {
  343. pControl->SetVisible(false);
  344. }
  345. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  346. if(pControl)
  347. {
  348. pControl->SetVisible(true);
  349. }
  350. }
  351. else
  352. {
  353. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  354. if(pControl)
  355. {
  356. pControl->SetVisible(true);
  357. }
  358. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  359. if(pControl)
  360. {
  361. pControl->SetVisible(false);
  362. }
  363. }
  364. }
  365. return lRes;
  366. }
  367. LRESULT CMainWnd::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  368. {
  369. int primaryMonitorWidth = ::GetSystemMetrics(SM_CXSCREEN);
  370. int primaryMonitorHeight = ::GetSystemMetrics(SM_CYSCREEN);
  371. MONITORINFO oMonitor = {};
  372. oMonitor.cbSize = sizeof(oMonitor);
  373. ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
  374. CDuiRect rcWork = oMonitor.rcWork;
  375. rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top);
  376. if(rcWork.right > primaryMonitorWidth)
  377. {
  378. rcWork.right = primaryMonitorWidth;
  379. }
  380. if(rcWork.bottom > primaryMonitorHeight)
  381. {
  382. rcWork.right = primaryMonitorHeight;
  383. }
  384. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  385. lpMMI->ptMaxPosition.x = rcWork.left;
  386. lpMMI->ptMaxPosition.y = rcWork.top;
  387. lpMMI->ptMaxSize.x = rcWork.right;
  388. lpMMI->ptMaxSize.y = rcWork.bottom;
  389. bHandled = FALSE;
  390. return 0;
  391. }
  392. LRESULT CMainWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  393. {
  394. SIZE szRoundCorner = m_pm.GetRoundCorner();
  395. if(!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  396. {
  397. CDuiRect rcWnd;
  398. ::GetWindowRect(*this, &rcWnd);
  399. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  400. rcWnd.right++;
  401. rcWnd.bottom++;
  402. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  403. ::SetWindowRgn(*this, hRgn, TRUE);
  404. ::DeleteObject(hRgn);
  405. }
  406. bHandled = FALSE;
  407. return 0;
  408. }
  409. LRESULT CMainWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  410. {
  411. bHandled = FALSE;
  412. return 0;
  413. }
  414. /*
  415. *这个是窗口被销毁的时候调用的
  416. **/
  417. LRESULT CMainWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  418. {
  419. //直接退出程序,或者退出登录都会执行这个
  420. m_push->Stop();
  421. bHandled = FALSE;
  422. return 0;
  423. }
  424. LRESULT CMainWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  425. {
  426. if(::IsIconic(*this))
  427. {
  428. bHandled = FALSE;
  429. }
  430. return (wParam == 0) ? TRUE : FALSE;
  431. }
  432. LRESULT CMainWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  433. {
  434. return 0;
  435. }
  436. LRESULT CMainWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  437. {
  438. return 0;
  439. }
  440. LRESULT CMainWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  441. {
  442. POINT pt;
  443. pt.x = GET_X_LPARAM(lParam);
  444. pt.y = GET_Y_LPARAM(lParam);
  445. ::ScreenToClient(*this, &pt);
  446. RECT rcClient;
  447. ::GetClientRect(*this, &rcClient);
  448. if(!::IsZoomed(*this))
  449. {
  450. RECT rcSizeBox = m_pm.GetSizeBox();
  451. if(pt.y < rcClient.top + rcSizeBox.top)
  452. {
  453. if(pt.x < rcClient.left + rcSizeBox.left)
  454. {
  455. return HTTOPLEFT;
  456. }
  457. if(pt.x > rcClient.right - rcSizeBox.right)
  458. {
  459. return HTTOPRIGHT;
  460. }
  461. return HTTOP;
  462. }
  463. else if(pt.y > rcClient.bottom - rcSizeBox.bottom)
  464. {
  465. if(pt.x < rcClient.left + rcSizeBox.left)
  466. {
  467. return HTBOTTOMLEFT;
  468. }
  469. if(pt.x > rcClient.right - rcSizeBox.right)
  470. {
  471. return HTBOTTOMRIGHT;
  472. }
  473. return HTBOTTOM;
  474. }
  475. if(pt.x < rcClient.left + rcSizeBox.left)
  476. {
  477. return HTLEFT;
  478. }
  479. if(pt.x > rcClient.right - rcSizeBox.right)
  480. {
  481. return HTRIGHT;
  482. }
  483. }
  484. RECT rcCaption = m_pm.GetCaptionRect();
  485. if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  486. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  487. {
  488. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  489. if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 &&
  490. _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 &&
  491. _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0)
  492. {
  493. return HTCAPTION;
  494. }
  495. }
  496. return HTCLIENT;
  497. }
  498. void CMainWnd::AddTrayIcon()
  499. {
  500. memset(&m_trayIcon, 0, sizeof(NOTIFYICONDATA));
  501. m_trayIcon.cbSize = sizeof(NOTIFYICONDATA);
  502. m_trayIcon.hIcon = ::LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON_DUILIB));
  503. m_trayIcon.hWnd = m_hWnd;
  504. lstrcpy(m_trayIcon.szTip, _T("智铺子收银系统"));
  505. m_trayIcon.uCallbackMessage = WM_SHOWTASK;
  506. m_trayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  507. Shell_NotifyIcon(NIM_ADD, &m_trayIcon);
  508. ShowWindow(SW_HIDE);
  509. }
  510. LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  511. {
  512. //如果在图标中单击左键则还原
  513. if(lParam == WM_LBUTTONDOWN)
  514. {
  515. //删除托盘图标
  516. Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
  517. //显示主窗口
  518. ShowWindow(SW_SHOWNORMAL);
  519. //窗口最大化
  520. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  521. }
  522. //如果在图标中单击右键则弹出声明式菜单
  523. if(lParam == WM_RBUTTONDOWN)
  524. {
  525. //获取鼠标坐标
  526. POINT pt;
  527. GetCursorPos(&pt);
  528. //右击后点别地可以清除“右击出来的菜单”
  529. SetForegroundWindow(m_hWnd);
  530. //托盘菜单 win32程序使用的是HMENU,如果是MFC程序可以使用CMenu
  531. HMENU hMenu;
  532. //生成托盘菜单
  533. hMenu = CreatePopupMenu();
  534. //添加菜单,关键在于设置的一个标识符 WM_ONCLOSE 点击后会用到
  535. AppendMenu(hMenu, MF_STRING, WM_ONCLOSE, _T("退出"));
  536. //弹出菜单,并把用户所选菜单项的标识符返回
  537. int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, NULL, m_hWnd, NULL);
  538. //如果标识符是WM_ONCLOSE则关闭
  539. if(cmd == WM_ONCLOSE)
  540. {
  541. m_trayIcon.hIcon = NULL;
  542. Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
  543. //退出程序
  544. ::PostQuitMessage(0);
  545. }
  546. }
  547. bHandled = true;
  548. return 0;
  549. }
  550. void CMainWnd::LoginOut(int mode)
  551. {
  552. CSetting::SetParam("setting_is_auto_login", "0", true);
  553. CLoginWnd* pLogin = new CLoginWnd();
  554. if(pLogin == NULL)
  555. {
  556. return;
  557. }
  558. //设置模式
  559. pLogin->SetMode(mode);
  560. pLogin->Create(NULL, _T("智铺子收银系统登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
  561. pLogin->SetIcon(IDI_ICON_DUILIB);
  562. pLogin->CenterWindow();
  563. ::ShowWindow(*pLogin, SW_SHOWNORMAL);
  564. Close();
  565. }
  566. CMessagePush* CMainWnd::getMessagePush()
  567. {
  568. return m_push;
  569. }
  570. void CMainWnd::SetInfopageWaimaiorderParam(std::string order_id, std::string order_no)
  571. {
  572. m_infopage_waimaiorder_id = order_id;
  573. m_infopage_waimaiorder_no = order_no;
  574. }