CLoginWnd.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  44. m_pm.Init(m_hWnd);
  45. m_pm.AddPreMessageFilter(this);
  46. CDialogBuilder builder;
  47. CControlUI* pRoot = builder.Create(_T("login.xml"), (UINT)0, NULL, &m_pm);
  48. ASSERT(pRoot && "Failed to parse XML");
  49. // 把这些控件绘制到本窗口上
  50. m_pm.AttachDialog(pRoot);
  51. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  52. m_pm.AddNotifier(this);
  53. Init();
  54. return 0;
  55. }
  56. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  57. {
  58. if (::IsIconic(*this)) bHandled = FALSE;
  59. return (wParam == 0) ? TRUE : FALSE;
  60. }
  61. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  62. {
  63. return 0;
  64. }
  65. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  66. {
  67. return 0;
  68. }
  69. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  70. {
  71. POINT pt; pt.x = GET_X_LPARAM(lParam); pt.y = GET_Y_LPARAM(lParam);
  72. ::ScreenToClient(*this, &pt);
  73. RECT rcClient;
  74. ::GetClientRect(*this, &rcClient);
  75. RECT rcCaption = m_pm.GetCaptionRect();
  76. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  77. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom) {
  78. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  79. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  80. return HTCAPTION;
  81. }
  82. return HTCLIENT;
  83. }
  84. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  85. {
  86. SIZE szRoundCorner = m_pm.GetRoundCorner();
  87. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0)) {
  88. CDuiRect rcWnd;
  89. ::GetWindowRect(*this, &rcWnd);
  90. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  91. rcWnd.right++; rcWnd.bottom++;
  92. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  93. ::SetWindowRgn(*this, hRgn, TRUE);
  94. ::DeleteObject(hRgn);
  95. }
  96. bHandled = FALSE;
  97. return 0;
  98. }
  99. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  100. {
  101. LRESULT lRes = 0;
  102. BOOL bHandled = TRUE;
  103. switch (uMsg) {
  104. case WM_CREATE: lRes = OnCreate(uMsg, wParam, lParam, bHandled); break;
  105. case WM_NCACTIVATE: lRes = OnNcActivate(uMsg, wParam, lParam, bHandled); break;
  106. case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
  107. case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
  108. case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
  109. case WM_SIZE: lRes = OnSize(uMsg, wParam, lParam, bHandled); break;
  110. default:
  111. bHandled = FALSE;
  112. }
  113. if (bHandled) return lRes;
  114. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
  115. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  116. }
  117. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  118. {
  119. if (uMsg == WM_KEYDOWN)
  120. {
  121. if (wParam == VK_RETURN)
  122. {
  123. CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
  124. if (pEdit->GetText().IsEmpty())
  125. {
  126. pEdit->SetFocus();
  127. }
  128. else
  129. {
  130. pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
  131. if (pEdit->GetText().IsEmpty())
  132. {
  133. pEdit->SetFocus();
  134. }
  135. else
  136. {
  137. this->HandleLogin();
  138. }
  139. }
  140. return true;
  141. }
  142. else if (wParam == VK_ESCAPE)
  143. {
  144. PostQuitMessage(0);
  145. return true;
  146. }
  147. }
  148. return false;
  149. }
  150. void HandleLogin();
  151. public:
  152. CPaintManagerUI m_pm;
  153. };