CMemberLoginWnd.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
  1. #include "../pch/pch.h"
  2. #include "CMemberLoginWnd.h"
  3. #include "CMessageboxWnd.h"
  4. #include "../helper/CSpeech.h"
  5. #include "../helper/MD5.h"
  6. #define WM_TIMER_WND_CLOSE 200001
  7. void CMemberLoginWnd::Init()
  8. {
  9. //::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE);
  10. }
  11. void CMemberLoginWnd::Notify(TNotifyUI& msg)
  12. {
  13. DuiLib::CDuiString senderName = msg.pSender->GetName();
  14. if (msg.sType == _T("click"))
  15. {
  16. if (msg.pSender->GetName() == _T("closebtn"))
  17. {
  18. StartClose();
  19. }
  20. else if (msg.pSender->GetName() == _T("shoukuanBtn"))
  21. {
  22. StartLogin();
  23. }
  24. else if (msg.pSender->GetName() == L"shoukuan_btn_saomazhifu")
  25. {
  26. CHorizontalLayoutUI* pFukuanmaLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_fukuanma_layout")));
  27. pFukuanmaLayout->SetVisible(true);
  28. CHorizontalLayoutUI* pShoujihaoLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_shoujihao_layout")));
  29. pShoujihaoLayout->SetVisible(false);
  30. CHorizontalLayoutUI* pShitikaLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_shitika_layout")));
  31. pShitikaLayout->SetVisible(false);
  32. CButtonUI* pFukuanmaBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_saomazhifu")));
  33. pFukuanmaBtn->SetTextColor(0xFF43A947);
  34. CButtonUI* pShoujihaoBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_shoujihao")));
  35. pShoujihaoBtn->SetTextColor(0xFF555555);
  36. CButtonUI* pShitikaBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_shitika")));
  37. pShitikaBtn->SetTextColor(0xFF555555);
  38. CControlUI* pFukuanmaLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_saomazhifu_line")));
  39. pFukuanmaLine->SetVisible(true);
  40. CControlUI* pShoujihaoLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_shoujihao_line")));
  41. pShoujihaoLine->SetVisible(false);
  42. CControlUI* pShitikaLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_shitika_line")));
  43. pShitikaLine->SetVisible(false);
  44. m_shoukuanModel = 1;
  45. }
  46. else if (msg.pSender->GetName() == L"shoukuan_btn_shoujihao")
  47. {
  48. CHorizontalLayoutUI* pFukuanmaLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_fukuanma_layout")));
  49. pFukuanmaLayout->SetVisible(false);
  50. CHorizontalLayoutUI* pShoujihaoLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_shoujihao_layout")));
  51. pShoujihaoLayout->SetVisible(true);
  52. CHorizontalLayoutUI* pShitikaLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_shitika_layout")));
  53. pShitikaLayout->SetVisible(false);
  54. CButtonUI* pFukuanmaBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_saomazhifu")));
  55. pFukuanmaBtn->SetTextColor(0xFF555555);
  56. CButtonUI* pShoujihaoBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_shoujihao")));
  57. pShoujihaoBtn->SetTextColor(0xFF43A947);
  58. CButtonUI* pShitikaBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_shitika")));
  59. pShitikaBtn->SetTextColor(0xFF555555);
  60. CControlUI* pFukuanmaLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_saomazhifu_line")));
  61. pFukuanmaLine->SetVisible(false);
  62. CControlUI* pShoujihaoLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_shoujihao_line")));
  63. pShoujihaoLine->SetVisible(true);
  64. CControlUI* pShitikaLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_shitika_line")));
  65. pShitikaLine->SetVisible(false);
  66. m_shoukuanModel = 2;
  67. m_pm.SetNextTabControl(false);
  68. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  69. pShoujihao->SetFocus();
  70. }
  71. else if (msg.pSender->GetName() == L"shoukuan_btn_shitika")
  72. {
  73. CHorizontalLayoutUI* pFukuanmaLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_fukuanma_layout")));
  74. pFukuanmaLayout->SetVisible(false);
  75. CHorizontalLayoutUI* pShoujihaoLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_shoujihao_layout")));
  76. pShoujihaoLayout->SetVisible(false);
  77. CHorizontalLayoutUI* pShitikaLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("fukuan_input_shitika_layout")));
  78. pShitikaLayout->SetVisible(true);
  79. CButtonUI* pFukuanmaBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_saomazhifu")));
  80. pFukuanmaBtn->SetTextColor(0xFF555555);
  81. CButtonUI* pShoujihaoBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_shoujihao")));
  82. pShoujihaoBtn->SetTextColor(0xFF555555);
  83. CButtonUI* pShitikaBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("shoukuan_btn_shitika")));
  84. pShitikaBtn->SetTextColor(0xFF43A947);
  85. CControlUI* pFukuanmaLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_saomazhifu_line")));
  86. pFukuanmaLine->SetVisible(false);
  87. CControlUI* pShoujihaoLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_shoujihao_line")));
  88. pShoujihaoLine->SetVisible(false);
  89. CControlUI* pShitikaLine = static_cast<CControlUI*>(m_pm.FindControl(_T("shoukuan_btn_shitika_line")));
  90. pShitikaLine->SetVisible(true);
  91. m_shoukuanModel = 3;
  92. }
  93. else if (senderName == L"jianpan_1")
  94. {
  95. CEditUI* curEdit;
  96. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  97. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  98. if (m_inputType == 1)
  99. {
  100. curEdit = pShoujihao;
  101. }
  102. else
  103. {
  104. curEdit = pPassword;
  105. }
  106. std::wstring wsReason = curEdit->GetText();
  107. wsReason += L"1";
  108. curEdit->SetText(wsReason.c_str());
  109. curEdit->SetFocus();
  110. }
  111. else if (senderName == L"jianpan_2")
  112. {
  113. CEditUI* curEdit;
  114. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  115. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  116. if (m_inputType == 1)
  117. {
  118. curEdit = pShoujihao;
  119. }
  120. else
  121. {
  122. curEdit = pPassword;
  123. }
  124. std::wstring wsReason = curEdit->GetText();
  125. wsReason += L"2";
  126. curEdit->SetText(wsReason.c_str());
  127. curEdit->SetFocus();
  128. }
  129. else if (senderName == L"jianpan_3")
  130. {
  131. CEditUI* curEdit;
  132. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  133. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  134. if (m_inputType == 1)
  135. {
  136. curEdit = pShoujihao;
  137. }
  138. else
  139. {
  140. curEdit = pPassword;
  141. }
  142. std::wstring wsReason = curEdit->GetText();
  143. wsReason += L"3";
  144. curEdit->SetText(wsReason.c_str());
  145. curEdit->SetFocus();
  146. }
  147. else if (senderName == L"jianpan_4")
  148. {
  149. CEditUI* curEdit;
  150. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  151. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  152. if (m_inputType == 1)
  153. {
  154. curEdit = pShoujihao;
  155. }
  156. else
  157. {
  158. curEdit = pPassword;
  159. }
  160. std::wstring wsReason = curEdit->GetText();
  161. wsReason += L"4";
  162. curEdit->SetText(wsReason.c_str());
  163. curEdit->SetFocus();
  164. }
  165. else if (senderName == L"jianpan_5")
  166. {
  167. CEditUI* curEdit;
  168. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  169. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  170. if (m_inputType == 1)
  171. {
  172. curEdit = pShoujihao;
  173. }
  174. else
  175. {
  176. curEdit = pPassword;
  177. }
  178. std::wstring wsReason = curEdit->GetText();
  179. wsReason += L"5";
  180. curEdit->SetText(wsReason.c_str());
  181. curEdit->SetFocus();
  182. }
  183. else if (senderName == L"jianpan_6")
  184. {
  185. CEditUI* curEdit;
  186. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  187. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  188. if (m_inputType == 1)
  189. {
  190. curEdit = pShoujihao;
  191. }
  192. else
  193. {
  194. curEdit = pPassword;
  195. }
  196. std::wstring wsReason = curEdit->GetText();
  197. wsReason += L"6";
  198. curEdit->SetText(wsReason.c_str());
  199. curEdit->SetFocus();
  200. }
  201. else if (senderName == L"jianpan_7")
  202. {
  203. CEditUI* curEdit;
  204. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  205. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  206. if (m_inputType == 1)
  207. {
  208. curEdit = pShoujihao;
  209. }
  210. else
  211. {
  212. curEdit = pPassword;
  213. }
  214. std::wstring wsReason = curEdit->GetText();
  215. wsReason += L"7";
  216. curEdit->SetText(wsReason.c_str());
  217. curEdit->SetFocus();
  218. }
  219. else if (senderName == L"jianpan_8")
  220. {
  221. CEditUI* curEdit;
  222. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  223. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  224. if (m_inputType == 1)
  225. {
  226. curEdit = pShoujihao;
  227. }
  228. else
  229. {
  230. curEdit = pPassword;
  231. }
  232. std::wstring wsReason = curEdit->GetText();
  233. wsReason += L"8";
  234. curEdit->SetText(wsReason.c_str());
  235. curEdit->SetFocus();
  236. }
  237. else if (senderName == L"jianpan_9")
  238. {
  239. CEditUI* curEdit;
  240. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  241. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  242. if (m_inputType == 1)
  243. {
  244. curEdit = pShoujihao;
  245. }
  246. else
  247. {
  248. curEdit = pPassword;
  249. }
  250. std::wstring wsReason = curEdit->GetText();
  251. wsReason += L"9";
  252. curEdit->SetText(wsReason.c_str());
  253. curEdit->SetFocus();
  254. }
  255. else if (senderName == L"jianpan_0")
  256. {
  257. CEditUI* curEdit;
  258. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  259. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  260. if (m_inputType == 1)
  261. {
  262. curEdit = pShoujihao;
  263. }
  264. else
  265. {
  266. curEdit = pPassword;
  267. }
  268. std::wstring wsReason = curEdit->GetText();
  269. wsReason += L"0";
  270. curEdit->SetText(wsReason.c_str());
  271. curEdit->SetFocus();
  272. }
  273. else if (senderName == L"jianpan_x")
  274. {
  275. CEditUI* curEdit;
  276. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  277. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  278. if (m_inputType == 1)
  279. {
  280. curEdit = pShoujihao;
  281. }
  282. else
  283. {
  284. curEdit = pPassword;
  285. }
  286. std::wstring wsReason = curEdit->GetText();
  287. wsReason = wsReason.substr(0, wsReason.length() - 1);
  288. curEdit->SetText(wsReason.c_str());
  289. curEdit->SetFocus();
  290. }
  291. else if (senderName == L"jianpan_qingkong")
  292. {
  293. CEditUI* curEdit;
  294. CEditUI* pShoujihao = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  295. CEditUI* pPassword = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  296. if (m_inputType == 1)
  297. {
  298. curEdit = pShoujihao;
  299. }
  300. else
  301. {
  302. curEdit = pPassword;
  303. }
  304. std::wstring wsReason = curEdit->GetText();
  305. wsReason.clear();
  306. curEdit->SetText(wsReason.c_str());
  307. curEdit->SetFocus();
  308. }
  309. }
  310. else if (msg.sType == _T("textchanged"))
  311. {
  312. if (senderName == L"shoujihao_edit")
  313. {
  314. //只能输入数字,其他的全部删除
  315. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  316. if (!m_pEdit->GetText().IsEmpty())
  317. {
  318. std::wstring ws_Value = m_pEdit->GetText();
  319. std::string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  320. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  321. {
  322. unsigned char tmp = strValue.at(nIndex);
  323. if (tmp > 57 || tmp < 48)
  324. {
  325. //ASCII码不是数字的都过滤掉
  326. strValue = strValue.substr(0, nIndex);
  327. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  328. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  329. break;
  330. }
  331. }
  332. }
  333. }
  334. if (senderName == L"password_edit")
  335. {
  336. //只能输入数字,其他的全部删除
  337. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  338. if (!m_pEdit->GetText().IsEmpty())
  339. {
  340. std::wstring ws_Value = m_pEdit->GetText();
  341. std::string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  342. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  343. {
  344. unsigned char tmp = strValue.at(nIndex);
  345. if (tmp > 57 || tmp < 48)
  346. {
  347. //ASCII码不是数字的都过滤掉
  348. strValue = strValue.substr(0, nIndex);
  349. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  350. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  351. break;
  352. }
  353. }
  354. }
  355. }
  356. }
  357. else if (msg.sType == _T("setfocus"))
  358. {
  359. if (senderName == L"shoujihao_edit")
  360. {
  361. m_inputType = 1;
  362. }
  363. else if (senderName == L"password_edit")
  364. {
  365. m_inputType = 2;
  366. }
  367. }
  368. }
  369. LRESULT CMemberLoginWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  370. {
  371. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  372. styleValue &= ~WS_CAPTION;
  373. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  374. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  375. m_pm.Init(m_hWnd);
  376. m_pm.AddPreMessageFilter(this);
  377. CDialogBuilder builder;
  378. CControlUI* pRoot = builder.Create(_T("member_login_dlg.xml"), (UINT)0, NULL, &m_pm);
  379. ASSERT(pRoot && "Failed to parse XML");
  380. // 把这些控件绘制到本窗口上
  381. m_pm.AttachDialog(pRoot);
  382. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  383. m_pm.AddNotifier(this);
  384. Init();
  385. return 0;
  386. }
  387. LRESULT CMemberLoginWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  388. {
  389. //销毁定时器
  390. KillTimer(m_hWnd, WM_TIMER_WND_CLOSE);
  391. bHandled = FALSE;
  392. return 0;
  393. }
  394. /*
  395. *这个是窗口被销毁的时候调用的
  396. **/
  397. LRESULT CMemberLoginWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  398. {
  399. bHandled = FALSE;
  400. return 0;
  401. }
  402. LRESULT CMemberLoginWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  403. {
  404. if (::IsIconic(*this))
  405. {
  406. bHandled = FALSE;
  407. }
  408. return (wParam == 0) ? TRUE : FALSE;
  409. }
  410. LRESULT CMemberLoginWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  411. {
  412. return 0;
  413. }
  414. LRESULT CMemberLoginWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  415. {
  416. return 0;
  417. }
  418. LRESULT CMemberLoginWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  419. {
  420. POINT pt;
  421. pt.x = GET_X_LPARAM(lParam);
  422. pt.y = GET_Y_LPARAM(lParam);
  423. ::ScreenToClient(*this, &pt);
  424. RECT rcClient;
  425. ::GetClientRect(*this, &rcClient);
  426. RECT rcCaption = m_pm.GetCaptionRect();
  427. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  428. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  429. {
  430. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  431. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  432. {
  433. return HTCAPTION;
  434. }
  435. }
  436. return HTCLIENT;
  437. }
  438. LRESULT CMemberLoginWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  439. {
  440. SIZE szRoundCorner = m_pm.GetRoundCorner();
  441. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  442. {
  443. CDuiRect rcWnd;
  444. ::GetWindowRect(*this, &rcWnd);
  445. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  446. rcWnd.right++;
  447. rcWnd.bottom++;
  448. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  449. ::SetWindowRgn(*this, hRgn, TRUE);
  450. ::DeleteObject(hRgn);
  451. }
  452. bHandled = FALSE;
  453. return 0;
  454. }
  455. LRESULT CMemberLoginWnd::OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  456. {
  457. bHandled = TRUE;
  458. return 0;
  459. }
  460. LRESULT CMemberLoginWnd::OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  461. {
  462. if (wParam != WM_TIMER_WND_CLOSE)
  463. {
  464. bHandled = FALSE;
  465. return 0;
  466. }
  467. if (m_shoukuan_status == 0 || m_shoukuan_status == 1)
  468. {
  469. }
  470. else if (m_shoukuan_status == 2)
  471. {
  472. }
  473. else if (m_shoukuan_status == 3)
  474. {
  475. m_timer_now--;
  476. if (m_timer_now > 0)
  477. {
  478. CLabelUI* attention = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_success_attention")));
  479. std::wstring ws_attention = L"按任意键关闭窗口," + std::to_wstring(m_timer_now) + L" 秒后自动关闭";
  480. attention->SetText(ws_attention.c_str());
  481. }
  482. else
  483. {
  484. Close(IDOK);
  485. }
  486. }
  487. else if (m_shoukuan_status == 4)
  488. {
  489. m_timer_now--;
  490. if (m_timer_now > 0)
  491. {
  492. CLabelUI* pFailMessage = static_cast<CLabelUI*>(m_pm.FindControl(_T("shouyin_pay_fail_attention")));
  493. std::wstring ws_fail_message = L"失败信息:" + m_fail_message + L",按任意键关闭窗口,";
  494. std::wstring ws_attention = ws_fail_message + std::to_wstring(m_timer_now) + L" 秒后自动关闭";
  495. pFailMessage->SetText(ws_attention.c_str());
  496. }
  497. else
  498. {
  499. Close(IDCANCEL);
  500. }
  501. }
  502. bHandled = TRUE;
  503. return 0;
  504. }
  505. LRESULT CMemberLoginWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  506. {
  507. LRESULT lRes = 0;
  508. BOOL bHandled = TRUE;
  509. switch (uMsg)
  510. {
  511. case WM_CREATE:
  512. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  513. break;
  514. case WM_CLOSE:
  515. lRes = OnClose(uMsg, wParam, lParam, bHandled);
  516. break;
  517. case WM_DESTROY:
  518. lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
  519. break;
  520. case WM_NCACTIVATE:
  521. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  522. break;
  523. case WM_NCCALCSIZE:
  524. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  525. break;
  526. case WM_NCPAINT:
  527. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  528. break;
  529. case WM_NCHITTEST:
  530. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  531. break;
  532. case WM_SIZE:
  533. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  534. break;
  535. case WM_MOUSEHOVER:
  536. lRes = OnMouseMove(uMsg, wParam, lParam, bHandled);
  537. break;
  538. case WM_SHOUKUAN_STATUS_SUCCESS:
  539. lRes = OnLoginSuccess(uMsg, wParam, lParam, bHandled);
  540. break;
  541. case WM_SHOUKUAN_STATUS_FAIL:
  542. lRes = OnLoginFail(uMsg, wParam, lParam, bHandled);
  543. break;
  544. case WM_TIMER:
  545. lRes = OnTimer(uMsg, wParam, lParam, bHandled);
  546. break;
  547. default:
  548. bHandled = FALSE;
  549. }
  550. if (bHandled)
  551. {
  552. return lRes;
  553. }
  554. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  555. {
  556. return lRes;
  557. }
  558. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  559. }
  560. LRESULT CMemberLoginWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  561. {
  562. if (uMsg == WM_KEYDOWN)
  563. {
  564. if (wParam == VK_RETURN)
  565. {
  566. if (m_shoukuan_status == 0)
  567. {
  568. if (m_shoukuanModel == 2)
  569. {
  570. StartLogin();
  571. }
  572. }
  573. else if (m_shoukuan_status == 1 || m_shoukuan_status == 2 || m_shoukuan_status == 5)
  574. {
  575. //正在支付的过程中,这个时候按Enter键,不做任何处理
  576. }
  577. else if (m_shoukuan_status == 3)
  578. {
  579. Close(IDOK);
  580. }
  581. else if (m_shoukuan_status == 4)
  582. {
  583. //Close(IDCANCEL);
  584. if (m_shoukuanModel == 2)
  585. {
  586. StartLogin();
  587. }
  588. }
  589. return true;
  590. }
  591. else if (wParam == VK_ESCAPE)
  592. {
  593. StartClose();
  594. return true;
  595. }
  596. if (m_shoukuan_status == 3)
  597. {
  598. Close(IDOK);
  599. return true;
  600. }
  601. else if (m_shoukuan_status == 4)
  602. {
  603. //Close(IDCANCEL);
  604. return true;
  605. }
  606. }
  607. return false;
  608. }
  609. void CMemberLoginWnd::SetCommonParams(std::map<std::string, std::string> params)
  610. {
  611. m_commonParams = params;
  612. }
  613. LRESULT CMemberLoginWnd::OnLoginSuccess(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  614. {
  615. Close(IDOK);
  616. bHandled = TRUE;
  617. return 0;
  618. }
  619. LRESULT CMemberLoginWnd::OnLoginFail(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  620. {
  621. CVerticalLayoutUI* paying_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_paying_layout")));
  622. paying_layout->SetVisible(false);
  623. CVerticalLayoutUI* before_pay_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_before_pay_layout")));
  624. before_pay_layout->SetVisible(true);
  625. CLabelUI* pLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuanresult")));
  626. pLabel->SetText((L"登录失败:" + m_fail_message).c_str());
  627. pLabel->SetVisible(true);
  628. SetFocus(m_hWnd);
  629. bHandled = TRUE;
  630. return 0;
  631. }
  632. void CMemberLoginWnd::StartLogin()
  633. {
  634. CLabelUI* pLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("shoukuanresult")));
  635. //先判断登录码的格式是否正确
  636. CEditUI* pShoujihaoEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("shoujihao_edit")));
  637. std::wstring ws_Shoujihao = pShoujihaoEdit->GetText();
  638. m_shoujihao = CLewaimaiString::UnicodeToUTF8(ws_Shoujihao);
  639. CEditUI* pPasswordEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("password_edit")));
  640. std::wstring ws_Password = pPasswordEdit->GetText();
  641. m_password = CLewaimaiString::UnicodeToUTF8(ws_Password);
  642. if (m_shoukuanModel == 2)
  643. {
  644. if (ws_Shoujihao.length() == 0)
  645. {
  646. pLabel->SetText(L"手机号不能为空");
  647. pLabel->SetVisible(true);
  648. return;
  649. }
  650. /*
  651. if (ws_Password.length() == 0)
  652. {
  653. pLabel->SetText(L"密码不能为空");
  654. pLabel->SetVisible(true);
  655. return;
  656. }
  657. }*/
  658. }
  659. //全部验证通过,就可以开始修改状态了
  660. m_shoukuan_status = 1;
  661. //不加这个的话,edit按回车之后样式有问题
  662. SetFocus(m_hWnd);
  663. CVerticalLayoutUI* before_pay_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_before_pay_layout")));
  664. before_pay_layout->SetVisible(false);
  665. CVerticalLayoutUI* paying_layout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("shoukuan_paying_layout")));
  666. paying_layout->SetVisible(true);
  667. //开启一个线程,开始处理登录
  668. std::thread(&CMemberLoginWnd::HandleLogin, this).detach();
  669. }
  670. void CMemberLoginWnd::StartClose()
  671. {
  672. if (m_shoukuan_status == 0)
  673. {
  674. //还没开始支付,直接退出
  675. Close(IDCANCEL);
  676. }
  677. else if (m_shoukuan_status == 1 || m_shoukuan_status == 5)
  678. {
  679. //不能做任何处理
  680. }
  681. else if (m_shoukuan_status == 2)
  682. {
  683. }
  684. else if (m_shoukuan_status == 3)
  685. {
  686. Sleep(100);
  687. Close(IDOK);
  688. }
  689. else if (m_shoukuan_status == 4)
  690. {
  691. Sleep(100);
  692. Close(IDCANCEL);
  693. }
  694. }
  695. void CMemberLoginWnd::HandleLogin()
  696. {
  697. std::string url;
  698. if (m_shoukuanModel == 1)
  699. {
  700. url = "/member/membercheckbyqrcode";
  701. m_commonParams["weixin_password"] = m_fukuanma;
  702. }
  703. else if (m_shoukuanModel == 2)
  704. {
  705. url = "/member/membercheckbyphone";
  706. m_commonParams["phone"] = m_shoujihao;
  707. }
  708. else if (m_shoukuanModel == 3)
  709. {
  710. url = "/member/membercheck";
  711. m_commonParams["card_identify"] = m_card_identify;
  712. }
  713. std::string response;
  714. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), m_commonParams, response);
  715. if (ret == false)
  716. {
  717. m_shoukuan_status = 4;
  718. m_fail_message = L"请求服务器失败,请检查网络设置!";
  719. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  720. return;
  721. }
  722. rapidjson::Document document;
  723. document.Parse(response.c_str());
  724. if (document.HasParseError())
  725. {
  726. LOG_INFO("parse response error!");
  727. m_shoukuan_status = 4;
  728. m_fail_message = L"服务器错误";
  729. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  730. return;
  731. }
  732. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  733. {
  734. LOG_INFO("json error!");
  735. m_shoukuan_status = 4;
  736. m_fail_message = L"服务器错误";
  737. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  738. return;
  739. }
  740. rapidjson::Value& v_errcode = document["errcode"];
  741. int errcode = v_errcode.GetInt();
  742. if (errcode != 0)
  743. {
  744. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  745. m_shoukuan_status = 4;
  746. std::string errmsg = document["errmsg"].GetString();
  747. m_fail_message = CLewaimaiString::UTF8ToUnicode(errmsg);
  748. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  749. return;
  750. }
  751. if (!document.HasMember("data"))
  752. {
  753. LOG_INFO("json error!");
  754. m_shoukuan_status = 4;
  755. m_fail_message = L"服务器错误";
  756. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  757. return;
  758. }
  759. rapidjson::Value& data = document["data"];
  760. rapidjson::Value& info = data["rows"][0];
  761. //支付成功
  762. m_shoukuan_status = 3;
  763. m_card_no = info["card_no"].GetString();
  764. m_card_identify = info["card_identify"].GetString();
  765. m_balance = info["balance"].GetString();
  766. m_name = info["name"].GetString();
  767. m_sex = info["sex"].GetString();
  768. m_birthday = info["birthday"].GetString();
  769. m_phone = info["phone"].GetString();
  770. m_address = info["address"].GetString();
  771. m_is_card = info["is_card"].GetString();
  772. m_member_id = info["id"].GetString();
  773. m_point = info["point"].GetString();
  774. m_open_no_card_payment = info["open_no_card_payment"].GetString();
  775. m_pay_password = info["pay_password"].GetString();
  776. m_freeze = info["freeze"].GetString();
  777. m_member_level = info["member_level"].GetString();
  778. m_member_level_name = info["member_level_name"].GetString();
  779. if (m_shoukuanModel == 2)
  780. {
  781. if (m_open_no_card_payment == "0")
  782. {
  783. m_shoukuan_status = 4;
  784. m_fail_message = L"该会员未开启手机号密码登录";
  785. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  786. return;
  787. }
  788. //进行支付密码比对
  789. if (m_pay_password != md5(m_password))
  790. {
  791. m_shoukuan_status = 4;
  792. m_fail_message = L"登录密码错误";
  793. PostMessage(WM_SHOUKUAN_STATUS_FAIL, 0, 0);
  794. return;
  795. }
  796. }
  797. PostMessage(WM_SHOUKUAN_STATUS_SUCCESS, 0, 0);
  798. }
  799. //处理键盘捕捉结果
  800. void CMemberLoginWnd::HandleTextCapture(std::string content)
  801. {
  802. if (m_shoukuanModel == 1)
  803. {
  804. m_fukuanma = content;
  805. StartLogin();
  806. }
  807. else if (m_shoukuanModel == 3)
  808. {
  809. m_card_identify = content;
  810. StartLogin();
  811. }
  812. }