CJiajiaWnd.cpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. #include "../pch/pch.h"
  2. #include "CjiajiaWnd.h"
  3. LRESULT CjiajiaWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  4. {
  5. POINT pt;
  6. pt.x = GET_X_LPARAM(lParam);
  7. pt.y = GET_Y_LPARAM(lParam);
  8. ::ScreenToClient(*this, &pt);
  9. RECT rcClient;
  10. ::GetClientRect(*this, &rcClient);
  11. RECT rcCaption = m_pm.GetCaptionRect();
  12. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  13. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  14. {
  15. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  16. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  17. {
  18. return HTCAPTION;
  19. }
  20. }
  21. return HTCLIENT;
  22. }
  23. LRESULT CjiajiaWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  24. {
  25. SIZE szRoundCorner = m_pm.GetRoundCorner();
  26. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  27. {
  28. CDuiRect rcWnd;
  29. ::GetWindowRect(*this, &rcWnd);
  30. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  31. rcWnd.right++;
  32. rcWnd.bottom++;
  33. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  34. ::SetWindowRgn(*this, hRgn, TRUE);
  35. ::DeleteObject(hRgn);
  36. }
  37. bHandled = FALSE;
  38. return 0;
  39. }
  40. LRESULT CjiajiaWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  41. {
  42. LRESULT lRes = 0;
  43. BOOL bHandled = TRUE;
  44. switch (uMsg)
  45. {
  46. case WM_CREATE:
  47. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  48. break;
  49. case WM_NCACTIVATE:
  50. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  51. break;
  52. case WM_NCCALCSIZE:
  53. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  54. break;
  55. case WM_NCPAINT:
  56. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  57. break;
  58. case WM_NCHITTEST:
  59. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  60. break;
  61. case WM_SIZE:
  62. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  63. break;
  64. default:
  65. bHandled = FALSE;
  66. }
  67. if (bHandled)
  68. {
  69. return lRes;
  70. }
  71. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  72. {
  73. return lRes;
  74. }
  75. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  76. }
  77. LRESULT CjiajiaWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  78. {
  79. if (uMsg == WM_KEYDOWN)
  80. {
  81. if (wParam == VK_RETURN)
  82. {
  83. StartYanzheng();
  84. return true;
  85. }
  86. else if (wParam == VK_ESCAPE)
  87. {
  88. Close(IDCANCEL);
  89. return true;
  90. }
  91. }
  92. return false;
  93. }
  94. LRESULT CjiajiaWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  95. {
  96. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  97. styleValue &= ~WS_CAPTION;
  98. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  99. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  100. m_pm.Init(m_hWnd);
  101. m_pm.AddPreMessageFilter(this);
  102. CDialogBuilder builder;
  103. CControlUI* pRoot = builder.Create(_T("jiajia_input_dlg.xml"), (UINT)0, NULL, &m_pm);
  104. ASSERT(pRoot && "Failed to parse XML");
  105. // 把这些控件绘制到本窗口上
  106. m_pm.AttachDialog(pRoot);
  107. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  108. m_pm.AddNotifier(this);
  109. Init();
  110. return 0;
  111. }
  112. void CjiajiaWnd::Notify(TNotifyUI& msg)
  113. {
  114. if (msg.sType == _T("click"))
  115. {
  116. DuiLib::CDuiString senderName = msg.pSender->GetName();
  117. if (senderName == _T("closebtn"))
  118. {
  119. Close(IDCANCEL);
  120. return;
  121. }
  122. else if (senderName == _T("save"))
  123. {
  124. StartYanzheng();
  125. }
  126. else if (senderName == L"jianpan_1")
  127. {
  128. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  129. wstring wsReason = pContent->GetText();
  130. wsReason += L"1";
  131. pContent->SetText(wsReason.c_str());
  132. pContent->SetFocus();
  133. }
  134. else if (senderName == L"jianpan_2")
  135. {
  136. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  137. wstring wsReason = pContent->GetText();
  138. wsReason += L"2";
  139. pContent->SetText(wsReason.c_str());
  140. pContent->SetFocus();
  141. }
  142. else if (senderName == L"jianpan_3")
  143. {
  144. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  145. wstring wsReason = pContent->GetText();
  146. wsReason += L"3";
  147. pContent->SetText(wsReason.c_str());
  148. pContent->SetFocus();
  149. }
  150. else if (senderName == L"jianpan_4")
  151. {
  152. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  153. wstring wsReason = pContent->GetText();
  154. wsReason += L"4";
  155. pContent->SetText(wsReason.c_str());
  156. pContent->SetFocus();
  157. }
  158. else if (senderName == L"jianpan_5")
  159. {
  160. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  161. wstring wsReason = pContent->GetText();
  162. wsReason += L"5";
  163. pContent->SetText(wsReason.c_str());
  164. pContent->SetFocus();
  165. }
  166. else if (senderName == L"jianpan_6")
  167. {
  168. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  169. wstring wsReason = pContent->GetText();
  170. wsReason += L"6";
  171. pContent->SetText(wsReason.c_str());
  172. pContent->SetFocus();
  173. }
  174. else if (senderName == L"jianpan_7")
  175. {
  176. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  177. wstring wsReason = pContent->GetText();
  178. wsReason += L"7";
  179. pContent->SetText(wsReason.c_str());
  180. pContent->SetFocus();
  181. }
  182. else if (senderName == L"jianpan_8")
  183. {
  184. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  185. wstring wsReason = pContent->GetText();
  186. wsReason += L"8";
  187. pContent->SetText(wsReason.c_str());
  188. pContent->SetFocus();
  189. }
  190. else if (senderName == L"jianpan_9")
  191. {
  192. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  193. wstring wsReason = pContent->GetText();
  194. wsReason += L"9";
  195. pContent->SetText(wsReason.c_str());
  196. pContent->SetFocus();
  197. }
  198. else if (senderName == L"jianpan_0")
  199. {
  200. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  201. wstring wsReason = pContent->GetText();
  202. wsReason += L"0";
  203. pContent->SetText(wsReason.c_str());
  204. pContent->SetFocus();
  205. }
  206. else if (senderName == L"jianpan_x")
  207. {
  208. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  209. wstring wsReason = pContent->GetText();
  210. wsReason = wsReason.substr(0, wsReason.length() - 1);
  211. pContent->SetText(wsReason.c_str());
  212. pContent->SetFocus();
  213. }
  214. else if (senderName == L"jianpan_qingkong")
  215. {
  216. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  217. wstring wsReason = pContent->GetText();
  218. wsReason.clear();
  219. pContent->SetText(wsReason.c_str());
  220. pContent->SetFocus();
  221. }
  222. }
  223. else if (msg.sType == _T("textchanged"))
  224. {
  225. //只能输入数字,其他的全部删除
  226. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  227. if (!m_pEdit->GetText().IsEmpty())
  228. {
  229. wstring ws_Value = m_pEdit->GetText();
  230. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  231. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  232. {
  233. unsigned char tmp = strValue.at(nIndex);
  234. if (tmp > 57 || tmp < 48)
  235. {
  236. //ASCII码不是数字的都过滤掉
  237. strValue = strValue.substr(0, nIndex);
  238. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  239. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  240. break;
  241. }
  242. }
  243. }
  244. }
  245. else if (msg.sType == L"windowinit")
  246. {
  247. m_pm.SetNextTabControl(false);
  248. CEditUI* pFukuanEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  249. pFukuanEdit->SetFocus();
  250. }
  251. }
  252. void CjiajiaWnd::Init()
  253. {
  254. }
  255. std::string CjiajiaWnd::getContent()
  256. {
  257. return m_content;
  258. }
  259. void CjiajiaWnd::SetTitle(std::wstring title)
  260. {
  261. CLabelUI* pLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("memo_dlg_title")));
  262. pLabel->SetText(title.c_str());
  263. }
  264. void CjiajiaWnd::StartYanzheng()
  265. {
  266. CEditUI* pContent = static_cast<CEditUI*>(m_pm.FindControl(_T("content")));
  267. wstring wsReason = pContent->GetText();
  268. m_content = CLewaimaiString::UnicodeToUTF8(wsReason);
  269. int zhekou = atoi(m_content.c_str());
  270. if (zhekou > 100 || zhekou < 0)
  271. {
  272. CLabelUI* pErrorInfo = static_cast<CLabelUI*>(m_pm.FindControl(_T("errinfo")));
  273. pErrorInfo->SetText(L"加价金额只能为0到100之间的整数");
  274. pErrorInfo->SetVisible(true);
  275. return;
  276. }
  277. Close(IDOK);
  278. }