CGameFrameWnd.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. #pragma once
  2. #include "../pch/pch.h"
  3. #include "CWaimaiOrderItemUI.h"
  4. #include "../order/CWaimaiOrder.h"
  5. #include "../tool/CPosPrinter.h"
  6. class CGameFrameWnd : public CWindowWnd, public INotifyUI
  7. {
  8. public:
  9. CGameFrameWnd() { };
  10. LPCTSTR GetWindowClassName() const
  11. {
  12. return _T("UIMainFrame");
  13. };
  14. UINT GetClassStyle() const
  15. {
  16. return CS_DBLCLKS;
  17. };
  18. void OnFinalMessage(HWND /*hWnd*/)
  19. {
  20. delete this;
  21. };
  22. void Init();
  23. void OnPrepare()
  24. {
  25. }
  26. void Notify(TNotifyUI& msg)
  27. {
  28. if(msg.sType == _T("windowinit"))
  29. {
  30. OnPrepare();
  31. }
  32. else if(msg.sType == _T("click"))
  33. {
  34. if(msg.pSender == m_pCloseBtn)
  35. {
  36. COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
  37. if(pControl && pControl->IsSelected() == false)
  38. {
  39. CControlUI* pFadeControl = m_pm.FindControl(_T("fadeEffect"));
  40. if(pFadeControl)
  41. {
  42. pFadeControl->SetVisible(true);
  43. }
  44. }
  45. else
  46. {
  47. /*Close()*/PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
  48. }
  49. return;
  50. }
  51. else if(msg.pSender == m_pMinBtn)
  52. {
  53. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  54. return;
  55. }
  56. else if(msg.pSender == m_pMaxBtn)
  57. {
  58. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  59. return;
  60. }
  61. else if(msg.pSender == m_pRestoreBtn)
  62. {
  63. SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
  64. return;
  65. }
  66. CDuiString name = msg.pSender->GetName();
  67. if(name == _T("quitbtn"))
  68. {
  69. /*Close()*/PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
  70. }
  71. else if(name == _T("returnhallbtn"))
  72. {
  73. CControlUI* pFadeControl = m_pm.FindControl(_T("fadeEffect"));
  74. if(pFadeControl)
  75. {
  76. pFadeControl->SetVisible(false);
  77. }
  78. COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
  79. pControl->Activate();
  80. pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("roomswitch")));
  81. if(pControl)
  82. {
  83. pControl->SetVisible(false);
  84. }
  85. }
  86. else if(name == _T("fontswitch"))
  87. {
  88. TFontInfo* pFontInfo = m_pm.GetDefaultFontInfo();
  89. if(pFontInfo->iSize < 18)
  90. {
  91. TFontInfo* pFontInfo = m_pm.GetFontInfo(0);
  92. if(pFontInfo)m_pm.SetDefaultFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold,
  93. pFontInfo->bUnderline, pFontInfo->bItalic);
  94. }
  95. else
  96. {
  97. TFontInfo* pFontInfo = m_pm.GetFontInfo(1);
  98. if(pFontInfo)m_pm.SetDefaultFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold,
  99. pFontInfo->bUnderline, pFontInfo->bItalic);
  100. }
  101. m_pm.GetRoot()->NeedUpdate();
  102. }
  103. else if(name == _T("leaveBtn") || name == _T("roomclosebtn"))
  104. {
  105. COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
  106. if(pControl)
  107. {
  108. pControl->Activate();
  109. pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("roomswitch")));
  110. if(pControl)
  111. {
  112. pControl->SetVisible(false);
  113. }
  114. }
  115. }
  116. else if (name == _T("waimai_order_list_print"))
  117. {
  118. //外卖订单的打印
  119. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent());
  120. std::string waimai_order_id = item->getOrderID();
  121. std::string waimai_order_no = item->getOrderNo();
  122. CWaimaiOrder order;
  123. order.InitData(waimai_order_id, waimai_order_no);
  124. CPosPrinter printer;
  125. printer.PrintWaimaiOrder(order);
  126. }
  127. }
  128. else if(msg.sType == _T("selectchanged"))
  129. {
  130. CDuiString name = msg.pSender->GetName();
  131. if(name == _T("hallswitch"))
  132. {
  133. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  134. if(pControl && pControl->GetCurSel() != 0)
  135. {
  136. pControl->SelectItem(0);
  137. }
  138. }
  139. }
  140. else if(msg.sType == _T("itemclick"))
  141. {
  142. }
  143. else if(msg.sType == _T("itemactivate"))
  144. {
  145. }
  146. else if(msg.sType == _T("itemselect"))
  147. {
  148. if(msg.pSender->GetName() == _T("chatCombo"))
  149. {
  150. CEditUI* pChatEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("chatEdit")));
  151. if(pChatEdit)
  152. {
  153. pChatEdit->SetText(msg.pSender->GetText());
  154. }
  155. static_cast<CComboUI*>(msg.pSender)->SelectItem(-1);
  156. }
  157. }
  158. }
  159. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  160. LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  161. {
  162. bHandled = FALSE;
  163. return 0;
  164. }
  165. LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  166. {
  167. ::PostQuitMessage(0L);
  168. bHandled = FALSE;
  169. return 0;
  170. }
  171. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  172. {
  173. if(::IsIconic(*this))
  174. {
  175. bHandled = FALSE;
  176. }
  177. return (wParam == 0) ? TRUE : FALSE;
  178. }
  179. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  180. {
  181. return 0;
  182. }
  183. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  184. {
  185. return 0;
  186. }
  187. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  188. {
  189. POINT pt;
  190. pt.x = GET_X_LPARAM(lParam);
  191. pt.y = GET_Y_LPARAM(lParam);
  192. ::ScreenToClient(*this, &pt);
  193. RECT rcClient;
  194. ::GetClientRect(*this, &rcClient);
  195. if(!::IsZoomed(*this))
  196. {
  197. RECT rcSizeBox = m_pm.GetSizeBox();
  198. if(pt.y < rcClient.top + rcSizeBox.top)
  199. {
  200. if(pt.x < rcClient.left + rcSizeBox.left)
  201. {
  202. return HTTOPLEFT;
  203. }
  204. if(pt.x > rcClient.right - rcSizeBox.right)
  205. {
  206. return HTTOPRIGHT;
  207. }
  208. return HTTOP;
  209. }
  210. else if(pt.y > rcClient.bottom - rcSizeBox.bottom)
  211. {
  212. if(pt.x < rcClient.left + rcSizeBox.left)
  213. {
  214. return HTBOTTOMLEFT;
  215. }
  216. if(pt.x > rcClient.right - rcSizeBox.right)
  217. {
  218. return HTBOTTOMRIGHT;
  219. }
  220. return HTBOTTOM;
  221. }
  222. if(pt.x < rcClient.left + rcSizeBox.left)
  223. {
  224. return HTLEFT;
  225. }
  226. if(pt.x > rcClient.right - rcSizeBox.right)
  227. {
  228. return HTRIGHT;
  229. }
  230. }
  231. RECT rcCaption = m_pm.GetCaptionRect();
  232. if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  233. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  234. {
  235. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  236. if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 &&
  237. _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 &&
  238. _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0)
  239. {
  240. return HTCAPTION;
  241. }
  242. }
  243. return HTCLIENT;
  244. }
  245. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  246. {
  247. SIZE szRoundCorner = m_pm.GetRoundCorner();
  248. if(!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  249. {
  250. CDuiRect rcWnd;
  251. ::GetWindowRect(*this, &rcWnd);
  252. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  253. rcWnd.right++;
  254. rcWnd.bottom++;
  255. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  256. ::SetWindowRgn(*this, hRgn, TRUE);
  257. ::DeleteObject(hRgn);
  258. }
  259. bHandled = FALSE;
  260. return 0;
  261. }
  262. LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  263. {
  264. int primaryMonitorWidth = ::GetSystemMetrics(SM_CXSCREEN);
  265. int primaryMonitorHeight = ::GetSystemMetrics(SM_CYSCREEN);
  266. MONITORINFO oMonitor = {};
  267. oMonitor.cbSize = sizeof(oMonitor);
  268. ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
  269. CDuiRect rcWork = oMonitor.rcWork;
  270. rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top);
  271. if(rcWork.right > primaryMonitorWidth)
  272. {
  273. rcWork.right = primaryMonitorWidth;
  274. }
  275. if(rcWork.bottom > primaryMonitorHeight)
  276. {
  277. rcWork.right = primaryMonitorHeight;
  278. }
  279. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  280. lpMMI->ptMaxPosition.x = rcWork.left;
  281. lpMMI->ptMaxPosition.y = rcWork.top;
  282. lpMMI->ptMaxSize.x = rcWork.right;
  283. lpMMI->ptMaxSize.y = rcWork.bottom;
  284. bHandled = FALSE;
  285. return 0;
  286. }
  287. LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  288. {
  289. // 有时会在收到WM_NCDESTROY后收到wParam为SC_CLOSE的WM_SYSCOMMAND
  290. if(wParam == SC_CLOSE)
  291. {
  292. ::PostQuitMessage(0L);
  293. bHandled = TRUE;
  294. return 0;
  295. }
  296. BOOL bZoomed = ::IsZoomed(*this);
  297. LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  298. if(::IsZoomed(*this) != bZoomed)
  299. {
  300. if(!bZoomed)
  301. {
  302. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  303. if(pControl)
  304. {
  305. pControl->SetVisible(false);
  306. }
  307. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  308. if(pControl)
  309. {
  310. pControl->SetVisible(true);
  311. }
  312. }
  313. else
  314. {
  315. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  316. if(pControl)
  317. {
  318. pControl->SetVisible(true);
  319. }
  320. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  321. if(pControl)
  322. {
  323. pControl->SetVisible(false);
  324. }
  325. }
  326. }
  327. return lRes;
  328. }
  329. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  330. {
  331. LRESULT lRes = 0;
  332. BOOL bHandled = TRUE;
  333. switch(uMsg)
  334. {
  335. case WM_CREATE:
  336. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  337. break;
  338. case WM_CLOSE:
  339. lRes = OnClose(uMsg, wParam, lParam, bHandled);
  340. break;
  341. case WM_DESTROY:
  342. lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
  343. break;
  344. case WM_NCACTIVATE:
  345. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  346. break;
  347. case WM_NCCALCSIZE:
  348. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  349. break;
  350. case WM_NCPAINT:
  351. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  352. break;
  353. case WM_NCHITTEST:
  354. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  355. break;
  356. case WM_SIZE:
  357. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  358. break;
  359. case WM_GETMINMAXINFO:
  360. lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled);
  361. break;
  362. case WM_SYSCOMMAND:
  363. lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
  364. break;
  365. default:
  366. bHandled = FALSE;
  367. }
  368. if(bHandled)
  369. {
  370. return lRes;
  371. }
  372. if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  373. {
  374. return lRes;
  375. }
  376. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  377. }
  378. public:
  379. CPaintManagerUI m_pm;
  380. private:
  381. CButtonUI* m_pCloseBtn;
  382. CButtonUI* m_pMaxBtn;
  383. CButtonUI* m_pRestoreBtn;
  384. CButtonUI* m_pMinBtn;
  385. //...
  386. };