CLoginWnd.h 4.6 KB

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