CGameFrameWnd.h 8.9 KB

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