CChufangSettingWnd.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #pragma once
  2. #include "../pch/pch.h"
  3. #include "CMainWnd.h"
  4. class CChufangSettingWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
  5. {
  6. public:
  7. CChufangSettingWnd()
  8. {
  9. }
  10. LPCTSTR GetWindowClassName() const
  11. {
  12. return _T("UILoginFrame");
  13. };
  14. UINT GetClassStyle() const
  15. {
  16. return UI_CLASSSTYLE_DIALOG;
  17. };
  18. void OnFinalMessage(HWND /*hWnd*/)
  19. {
  20. //WindowImplBase::OnFinalMessage(hWnd);
  21. m_pm.RemovePreMessageFilter(this);
  22. delete this;
  23. };
  24. void Init()
  25. {
  26. }
  27. void Notify(TNotifyUI& msg)
  28. {
  29. if (msg.sType == _T("click"))
  30. {
  31. DuiLib::CDuiString senderName = msg.pSender->GetName();
  32. if (senderName == _T("chufang_setting_closebtn"))
  33. {
  34. Close(IDCANCEL);
  35. return;
  36. }
  37. else if (senderName == _T("chufang_setting_save"))
  38. {
  39. //开始保存厨房打印机的数据
  40. CEditUI* pName = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
  41. wstring wsName = pName->GetText();
  42. CEditUI* pIP = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
  43. wstring wsIP = pIP->GetText();
  44. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
  45. wstring wsGuige;
  46. if (com->GetCurSel() == 0)
  47. {
  48. wsGuige = L"58";
  49. }
  50. else
  51. {
  52. wsGuige = L"80";
  53. }
  54. CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
  55. wstring wsFendan;
  56. if (pFendan->IsSelected())
  57. {
  58. wsFendan = L"1";
  59. }
  60. else
  61. {
  62. wsFendan = L"0";
  63. }
  64. CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
  65. wstring wsFenlei;
  66. if (pFenlei->IsSelected())
  67. {
  68. wsFenlei = L"1";
  69. }
  70. else
  71. {
  72. wsFenlei = L"0";
  73. }
  74. //保存数据到数据库
  75. std::string name = CLewaimaiString::UnicodeToUTF8(wsName);
  76. std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP);
  77. std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige);
  78. std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan);
  79. std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei);
  80. std::string fenlei_ids = "";
  81. CSetting::AddChufangPrinter(name, ip, guige, fendan, fenlei, fenlei_ids, true);
  82. Close(IDOK);
  83. return;
  84. }
  85. }
  86. }
  87. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  88. {
  89. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  90. styleValue &= ~WS_CAPTION;
  91. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  92. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  93. m_pm.Init(m_hWnd);
  94. m_pm.AddPreMessageFilter(this);
  95. CDialogBuilder builder;
  96. CControlUI* pRoot = builder.Create(_T("chufang_printer_setting.xml"), (UINT)0, NULL, &m_pm);
  97. ASSERT(pRoot && "Failed to parse XML");
  98. // 把这些控件绘制到本窗口上
  99. m_pm.AttachDialog(pRoot);
  100. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  101. m_pm.AddNotifier(this);
  102. Init();
  103. return 0;
  104. }
  105. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  106. {
  107. if (::IsIconic(*this))
  108. {
  109. bHandled = FALSE;
  110. }
  111. return (wParam == 0) ? TRUE : FALSE;
  112. }
  113. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  114. {
  115. return 0;
  116. }
  117. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  118. {
  119. return 0;
  120. }
  121. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  122. {
  123. POINT pt;
  124. pt.x = GET_X_LPARAM(lParam);
  125. pt.y = GET_Y_LPARAM(lParam);
  126. ::ScreenToClient(*this, &pt);
  127. RECT rcClient;
  128. ::GetClientRect(*this, &rcClient);
  129. RECT rcCaption = m_pm.GetCaptionRect();
  130. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  131. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  132. {
  133. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  134. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  135. {
  136. return HTCAPTION;
  137. }
  138. }
  139. return HTCLIENT;
  140. }
  141. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  142. {
  143. SIZE szRoundCorner = m_pm.GetRoundCorner();
  144. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  145. {
  146. CDuiRect rcWnd;
  147. ::GetWindowRect(*this, &rcWnd);
  148. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  149. rcWnd.right++;
  150. 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 HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  159. {
  160. LRESULT lRes = 0;
  161. BOOL bHandled = TRUE;
  162. switch (uMsg)
  163. {
  164. case WM_CREATE:
  165. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  166. break;
  167. case WM_NCACTIVATE:
  168. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  169. break;
  170. case WM_NCCALCSIZE:
  171. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  172. break;
  173. case WM_NCPAINT:
  174. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  175. break;
  176. case WM_NCHITTEST:
  177. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  178. break;
  179. case WM_SIZE:
  180. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  181. break;
  182. default:
  183. bHandled = FALSE;
  184. }
  185. if (bHandled)
  186. {
  187. return lRes;
  188. }
  189. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  190. {
  191. return lRes;
  192. }
  193. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  194. }
  195. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  196. {
  197. if (uMsg == WM_KEYDOWN)
  198. {
  199. if (wParam == VK_RETURN)
  200. {
  201. CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("accountedit")));
  202. if (pEdit->GetText().IsEmpty())
  203. {
  204. pEdit->SetFocus();
  205. }
  206. else
  207. {
  208. pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("pwdedit")));
  209. if (pEdit->GetText().IsEmpty())
  210. {
  211. pEdit->SetFocus();
  212. }
  213. else
  214. {
  215. this->HandleLogin();
  216. }
  217. }
  218. return true;
  219. }
  220. else if (wParam == VK_ESCAPE)
  221. {
  222. PostQuitMessage(0);
  223. return true;
  224. }
  225. }
  226. return false;
  227. }
  228. void HandleLogin();
  229. public:
  230. CPaintManagerUI m_pm;
  231. };