CGameFrameWnd.h 12 KB

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