CGameFrameWnd.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. #pragma once
  2. #include "../pch/pch.h"
  3. class CGameFrameWnd : public CWindowWnd, public INotifyUI
  4. {
  5. public:
  6. CGameFrameWnd() { };
  7. LPCTSTR GetWindowClassName() const { return _T("UIMainFrame"); };
  8. UINT GetClassStyle() const { return CS_DBLCLKS; };
  9. void OnFinalMessage(HWND /*hWnd*/) { delete this; };
  10. void Init()
  11. {
  12. m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
  13. m_pMaxBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("maxbtn")));
  14. m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
  15. m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
  16. }
  17. void OnPrepare()
  18. {
  19. }
  20. void Notify(TNotifyUI& msg)
  21. {
  22. if (msg.sType == _T("windowinit")) OnPrepare();
  23. else if (msg.sType == _T("click")) {
  24. if (msg.pSender == m_pCloseBtn) {
  25. COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
  26. if (pControl && pControl->IsSelected() == false) {
  27. CControlUI* pFadeControl = m_pm.FindControl(_T("fadeEffect"));
  28. if (pFadeControl) pFadeControl->SetVisible(true);
  29. }
  30. else {
  31. /*Close()*/PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
  32. }
  33. return;
  34. }
  35. else if (msg.pSender == m_pMinBtn) { SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); return; }
  36. else if (msg.pSender == m_pMaxBtn) { SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0); return; }
  37. else if (msg.pSender == m_pRestoreBtn) { SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0); return; }
  38. CDuiString name = msg.pSender->GetName();
  39. if (name == _T("quitbtn")) {
  40. /*Close()*/PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
  41. }
  42. else if (name == _T("returnhallbtn")) {
  43. CControlUI* pFadeControl = m_pm.FindControl(_T("fadeEffect"));
  44. if (pFadeControl) pFadeControl->SetVisible(false);
  45. COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
  46. pControl->Activate();
  47. pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("roomswitch")));
  48. if (pControl) pControl->SetVisible(false);
  49. }
  50. else if (name == _T("fontswitch")) {
  51. TFontInfo* pFontInfo = m_pm.GetDefaultFontInfo();
  52. if (pFontInfo->iSize < 18) {
  53. TFontInfo* pFontInfo = m_pm.GetFontInfo(0);
  54. if (pFontInfo)m_pm.SetDefaultFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold,
  55. pFontInfo->bUnderline, pFontInfo->bItalic);
  56. }
  57. else {
  58. TFontInfo* pFontInfo = m_pm.GetFontInfo(1);
  59. if (pFontInfo)m_pm.SetDefaultFont(pFontInfo->sFontName, pFontInfo->iSize, pFontInfo->bBold,
  60. pFontInfo->bUnderline, pFontInfo->bItalic);
  61. }
  62. m_pm.GetRoot()->NeedUpdate();
  63. }
  64. else if (name == _T("leaveBtn") || name == _T("roomclosebtn")) {
  65. COptionUI* pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("hallswitch")));
  66. if (pControl) {
  67. pControl->Activate();
  68. pControl = static_cast<COptionUI*>(m_pm.FindControl(_T("roomswitch")));
  69. if (pControl) pControl->SetVisible(false);
  70. }
  71. }
  72. }
  73. else if (msg.sType == _T("selectchanged")) {
  74. CDuiString name = msg.pSender->GetName();
  75. if (name == _T("hallswitch")) {
  76. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  77. if (pControl && pControl->GetCurSel() != 0) pControl->SelectItem(0);
  78. }
  79. }
  80. else if (msg.sType == _T("itemclick")) {
  81. }
  82. else if (msg.sType == _T("itemactivate")) {
  83. }
  84. else if (msg.sType == _T("itemselect")) {
  85. if (msg.pSender->GetName() == _T("chatCombo")) {
  86. CEditUI* pChatEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("chatEdit")));
  87. if (pChatEdit) pChatEdit->SetText(msg.pSender->GetText());
  88. static_cast<CComboUI*>(msg.pSender)->SelectItem(-1);
  89. }
  90. }
  91. }
  92. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  93. LRESULT OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  94. {
  95. bHandled = FALSE;
  96. return 0;
  97. }
  98. LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  99. {
  100. ::PostQuitMessage(0L);
  101. bHandled = FALSE;
  102. return 0;
  103. }
  104. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  105. {
  106. if (::IsIconic(*this)) bHandled = FALSE;
  107. return (wParam == 0) ? TRUE : FALSE;
  108. }
  109. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  110. {
  111. return 0;
  112. }
  113. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  114. {
  115. return 0;
  116. }
  117. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  118. {
  119. POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
  120. ::ScreenToClient(*this, &pt);
  121. RECT rcClient;
  122. ::GetClientRect(*this, &rcClient);
  123. if (!::IsZoomed(*this)) {
  124. RECT rcSizeBox = m_pm.GetSizeBox();
  125. if (pt.y < rcClient.top + rcSizeBox.top) {
  126. if (pt.x < rcClient.left + rcSizeBox.left) return HTTOPLEFT;
  127. if (pt.x > rcClient.right - rcSizeBox.right) return HTTOPRIGHT;
  128. return HTTOP;
  129. }
  130. else if (pt.y > rcClient.bottom - rcSizeBox.bottom) {
  131. if (pt.x < rcClient.left + rcSizeBox.left) return HTBOTTOMLEFT;
  132. if (pt.x > rcClient.right - rcSizeBox.right) return HTBOTTOMRIGHT;
  133. return HTBOTTOM;
  134. }
  135. if (pt.x < rcClient.left + rcSizeBox.left) return HTLEFT;
  136. if (pt.x > rcClient.right - rcSizeBox.right) return HTRIGHT;
  137. }
  138. RECT rcCaption = m_pm.GetCaptionRect();
  139. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  140. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom) {
  141. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  142. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 &&
  143. _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 &&
  144. _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0)
  145. return HTCAPTION;
  146. }
  147. return HTCLIENT;
  148. }
  149. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  150. {
  151. SIZE szRoundCorner = m_pm.GetRoundCorner();
  152. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0)) {
  153. CDuiRect rcWnd;
  154. ::GetWindowRect(*this, &rcWnd);
  155. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  156. rcWnd.right++; rcWnd.bottom++;
  157. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  158. ::SetWindowRgn(*this, hRgn, TRUE);
  159. ::DeleteObject(hRgn);
  160. }
  161. bHandled = FALSE;
  162. return 0;
  163. }
  164. LRESULT OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  165. {
  166. int primaryMonitorWidth = ::GetSystemMetrics(SM_CXSCREEN);
  167. int primaryMonitorHeight = ::GetSystemMetrics(SM_CYSCREEN);
  168. MONITORINFO oMonitor = {};
  169. oMonitor.cbSize = sizeof(oMonitor);
  170. ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
  171. CDuiRect rcWork = oMonitor.rcWork;
  172. rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top);
  173. if (rcWork.right > primaryMonitorWidth) rcWork.right = primaryMonitorWidth;
  174. if (rcWork.bottom > primaryMonitorHeight) rcWork.right = primaryMonitorHeight;
  175. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  176. lpMMI->ptMaxPosition.x = rcWork.left;
  177. lpMMI->ptMaxPosition.y = rcWork.top;
  178. lpMMI->ptMaxSize.x = rcWork.right;
  179. lpMMI->ptMaxSize.y = rcWork.bottom;
  180. bHandled = FALSE;
  181. return 0;
  182. }
  183. LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  184. {
  185. // 有时会在收到WM_NCDESTROY后收到wParam为SC_CLOSE的WM_SYSCOMMAND
  186. if (wParam == SC_CLOSE) {
  187. ::PostQuitMessage(0L);
  188. bHandled = TRUE;
  189. return 0;
  190. }
  191. BOOL bZoomed = ::IsZoomed(*this);
  192. LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  193. if (::IsZoomed(*this) != bZoomed) {
  194. if (!bZoomed) {
  195. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  196. if (pControl) pControl->SetVisible(false);
  197. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  198. if (pControl) pControl->SetVisible(true);
  199. }
  200. else {
  201. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  202. if (pControl) pControl->SetVisible(true);
  203. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  204. if (pControl) pControl->SetVisible(false);
  205. }
  206. }
  207. return lRes;
  208. }
  209. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  210. {
  211. LRESULT lRes = 0;
  212. BOOL bHandled = TRUE;
  213. switch (uMsg) {
  214. case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;
  215. case WM_CLOSE: lRes = OnClose(uMsg, wParam, lParam, bHandled); break;
  216. case WM_DESTROY: lRes = OnDestroy(uMsg, wParam, lParam, bHandled); break;
  217. case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;
  218. case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
  219. case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
  220. case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
  221. case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break;
  222. case WM_GETMINMAXINFO: lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled); break;
  223. case WM_SYSCOMMAND: lRes = OnSysCommand(uMsg, wParam, lParam, bHandled); break;
  224. default:
  225. bHandled = FALSE;
  226. }
  227. if (bHandled) return lRes;
  228. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
  229. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  230. }
  231. public:
  232. CPaintManagerUI m_pm;
  233. private:
  234. CButtonUI* m_pCloseBtn;
  235. CButtonUI* m_pMaxBtn;
  236. CButtonUI* m_pRestoreBtn;
  237. CButtonUI* m_pMinBtn;
  238. //...
  239. };