CLoginWnd.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #pragma once
  2. #include "pch/pch.h"
  3. #include "CGameFrameWnd.h"
  4. class CLoginFrameWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
  5. {
  6. public:
  7. CLoginFrameWnd()
  8. {
  9. }
  10. LPCTSTR GetWindowClassName() const { return _T("UILoginFrame"); };
  11. UINT GetClassStyle() const { return UI_CLASSSTYLE_DIALOG; };
  12. void OnFinalMessage(HWND /*hWnd*/)
  13. {
  14. m_pm.RemovePreMessageFilter(this);
  15. delete this;
  16. };
  17. void Init() {
  18. CEditUI* pAccountEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
  19. if (pAccountEdit) pAccountEdit->SetText(_T("请输入智铺子员工账号"));
  20. pAccountEdit->SetFocus();
  21. }
  22. void Notify(TNotifyUI& msg)
  23. {
  24. if (msg.sType == _T("click"))
  25. {
  26. if (msg.pSender->GetName() == _T("closebtn"))
  27. {
  28. PostQuitMessage(0);
  29. return;
  30. }
  31. else if (msg.pSender->GetName() == _T("loginBtn"))
  32. {
  33. HandleLogin();
  34. return;
  35. }
  36. }
  37. }
  38. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  39. {
  40. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  41. styleValue &= ~WS_CAPTION;
  42. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  43. m_pm.Init(m_hWnd);
  44. m_pm.AddPreMessageFilter(this);
  45. CDialogBuilder builder;
  46. CDialogBuilderCallbackEx cb;
  47. CControlUI* pRoot = builder.Create(_T("login.xml"), (UINT)0, &cb, &m_pm);
  48. ASSERT(pRoot && "Failed to parse XML");
  49. m_pm.AttachDialog(pRoot);
  50. m_pm.AddNotifier(this);
  51. Init();
  52. return 0;
  53. }
  54. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  55. {
  56. if (::IsIconic(*this)) bHandled = FALSE;
  57. return (wParam == 0) ? TRUE : FALSE;
  58. }
  59. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  60. {
  61. return 0;
  62. }
  63. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  64. {
  65. return 0;
  66. }
  67. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  68. {
  69. POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
  70. ::ScreenToClient(*this, &pt);
  71. RECT rcClient;
  72. ::GetClientRect(*this, &rcClient);
  73. RECT rcCaption = m_pm.GetCaptionRect();
  74. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  75. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom) {
  76. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  77. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  78. return HTCAPTION;
  79. }
  80. return HTCLIENT;
  81. }
  82. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  83. {
  84. SIZE szRoundCorner = m_pm.GetRoundCorner();
  85. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0)) {
  86. CDuiRect rcWnd;
  87. ::GetWindowRect(*this, &rcWnd);
  88. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  89. rcWnd.right++; rcWnd.bottom++;
  90. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  91. ::SetWindowRgn(*this, hRgn, TRUE);
  92. ::DeleteObject(hRgn);
  93. }
  94. bHandled = FALSE;
  95. return 0;
  96. }
  97. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  98. {
  99. LRESULT lRes = 0;
  100. BOOL bHandled = TRUE;
  101. switch (uMsg) {
  102. case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;
  103. case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;
  104. case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
  105. case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
  106. case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
  107. case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break;
  108. default:
  109. bHandled = FALSE;
  110. }
  111. if (bHandled) return lRes;
  112. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
  113. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  114. }
  115. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  116. {
  117. if (uMsg == WM_KEYDOWN)
  118. {
  119. if (wParam == VK_RETURN)
  120. {
  121. CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
  122. if (pEdit->GetText().IsEmpty())
  123. {
  124. pEdit->SetFocus();
  125. }
  126. else
  127. {
  128. pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
  129. if (pEdit->GetText().IsEmpty())
  130. {
  131. pEdit->SetFocus();
  132. }
  133. else
  134. {
  135. this->HandleLogin();
  136. }
  137. }
  138. return true;
  139. }
  140. else if (wParam == VK_ESCAPE)
  141. {
  142. PostQuitMessage(0);
  143. return true;
  144. }
  145. }
  146. return false;
  147. }
  148. void HandleLogin()
  149. {
  150. CGameFrameWnd* pFrame = new CGameFrameWnd();
  151. if (pFrame == NULL)
  152. {
  153. return;
  154. }
  155. pFrame->SetIcon(IDI_ICON_DUILIB);
  156. pFrame->Create(NULL, _T("游戏中心"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 1024, 738);
  157. pFrame->CenterWindow();
  158. ::ShowWindow(*pFrame, SW_SHOWMAXIMIZED);
  159. Close();
  160. }
  161. public:
  162. CPaintManagerUI m_pm;
  163. };