CFupingWnd.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. #include "../pch/pch.h"
  2. #include "CFupingWnd.h"
  3. #include "../page/CDiandanPageUI.h"
  4. LRESULT CFupingWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  5. {
  6. POINT pt;
  7. pt.x = GET_X_LPARAM(lParam);
  8. pt.y = GET_Y_LPARAM(lParam);
  9. ::ScreenToClient(*this, &pt);
  10. RECT rcClient;
  11. ::GetClientRect(*this, &rcClient);
  12. RECT rcCaption = m_pm.GetCaptionRect();
  13. if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  14. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  15. {
  16. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  17. if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
  18. {
  19. return HTCAPTION;
  20. }
  21. }
  22. return HTCLIENT;
  23. }
  24. LRESULT CFupingWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  25. {
  26. SIZE szRoundCorner = m_pm.GetRoundCorner();
  27. if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  28. {
  29. CDuiRect rcWnd;
  30. ::GetWindowRect(*this, &rcWnd);
  31. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  32. rcWnd.right++;
  33. rcWnd.bottom++;
  34. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  35. ::SetWindowRgn(*this, hRgn, TRUE);
  36. ::DeleteObject(hRgn);
  37. }
  38. bHandled = FALSE;
  39. return 0;
  40. }
  41. LRESULT CFupingWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  42. {
  43. LRESULT lRes = 0;
  44. BOOL bHandled = TRUE;
  45. switch (uMsg)
  46. {
  47. case WM_CREATE:
  48. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  49. break;
  50. case WM_NCACTIVATE:
  51. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  52. break;
  53. case WM_NCCALCSIZE:
  54. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  55. break;
  56. case WM_NCPAINT:
  57. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  58. break;
  59. case WM_NCHITTEST:
  60. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  61. break;
  62. case WM_SIZE:
  63. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  64. break;
  65. default:
  66. bHandled = FALSE;
  67. }
  68. if (bHandled)
  69. {
  70. return lRes;
  71. }
  72. if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  73. {
  74. return lRes;
  75. }
  76. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  77. }
  78. LRESULT CFupingWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
  79. {
  80. if (uMsg == WM_KEYDOWN)
  81. {
  82. if (wParam == VK_RETURN)
  83. {
  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 CFupingWnd::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("fuping_wnd.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 CFupingWnd::Notify(TNotifyUI& msg)
  113. {
  114. }
  115. //刚启动程序初始化副屏窗口的时候执行,app生命周期只执行一次
  116. void CFupingWnd::Init()
  117. {
  118. m_is_work = true;
  119. //启动轮播图展示任务
  120. std::thread(&CFupingWnd::HandleFupingImage, this).detach();
  121. }
  122. void CFupingWnd::HandleFupingImage()
  123. {
  124. while (m_is_work == true)
  125. {
  126. if (CShopinfo::GetInstance()->m_shop_name.size() == 0)
  127. {
  128. //还没登录成功,没拿到店铺名字,等待
  129. CSystem::my_sleep(1);
  130. continue;
  131. }
  132. //更新店铺名字
  133. CLabelUI* nameControl = static_cast<CLabelUI*>(m_pm.FindControl(L"shopname"));
  134. std::wstring shopname = CLewaimaiString::UTF8ToUnicode(CShopinfo::GetInstance()->m_shop_name);
  135. nameControl->SetText(shopname.c_str());
  136. std::vector<std::wstring> lunbo_img_paths = CShopinfo::GetInstance()->m_lunbo_img_paths;
  137. if (lunbo_img_paths.size() == 0)
  138. {
  139. //有可能后台没设置轮播图,有可能还没请求到后台最新数据,等待
  140. CSystem::my_sleep(2);
  141. continue;
  142. }
  143. //然后开始处理轮播图
  144. if (m_curImageNum > lunbo_img_paths.size() - 1)
  145. {
  146. m_curImageNum = 0;
  147. }
  148. std::wstring image_path = lunbo_img_paths[m_curImageNum];
  149. //判断图片是否存在
  150. if (!CSystem::IsFileExist(image_path))
  151. {
  152. //轮播图的图片还未下载好
  153. CSystem::my_sleep(3);
  154. //3秒后还没下载好,处理下一张
  155. m_curImageNum++;
  156. continue;
  157. }
  158. //轮播图的图片已经下载好了,那么就直接渲染
  159. CControlUI* imageControl = static_cast<CControlUI*>(m_pm.FindControl(L"lunbo_image"));
  160. imageControl->SetBkImage(image_path.c_str());
  161. //等待3秒钟,换下一张
  162. CSystem::my_sleep(3);
  163. //3秒轮播一次
  164. m_curImageNum++;
  165. continue;
  166. }
  167. //这个线程结束后,释放自己
  168. delete this;
  169. }
  170. //刷新副屏显示
  171. void CFupingWnd::UpdateShow(CDiandanOrder& order, double total_youhui, double total_price, double dabao_money)
  172. {
  173. //先清空当前的显示
  174. CListUI* pList = static_cast<CListUI*>(m_pm.FindControl(_T("list_diandan_cart")));
  175. pList->RemoveAll();
  176. //然后依次渲染所有的
  177. int nItemNum = order.getItemNum();
  178. for (int i = 0; i < nItemNum; i++)
  179. {
  180. CDiandanOrderItem item = order.getDiandanOrderItem(i);
  181. CDialogBuilder builder;
  182. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("diandan_cart_item.xml"), (UINT)0, NULL, &m_pm));
  183. pList->Add(pEle);
  184. if (item.m_is_taocan)
  185. {
  186. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  187. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  188. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  189. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  190. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  191. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  192. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  193. pEle->SetFixedHeight(84);
  194. pNature->SetVisible(true);
  195. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
  196. }
  197. else
  198. {
  199. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  200. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  201. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  202. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  203. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  204. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  205. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  206. if (item.is_nature)
  207. {
  208. pEle->SetFixedHeight(84);
  209. pNature->SetVisible(true);
  210. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
  211. }
  212. else
  213. {
  214. pEle->SetFixedHeight(42);
  215. pNature->SetVisible(false);
  216. }
  217. }
  218. }
  219. //刷新优惠展示
  220. CHorizontalLayoutUI* pYouhuiLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi_layout")));
  221. CLabelUI* pYouhuiLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi")));
  222. if (total_youhui > 0)
  223. {
  224. wstring youhuilabel = L"已优惠 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_youhui, 2)) + L" 元";
  225. pYouhuiLabel->SetText(youhuilabel.c_str());
  226. pYouhuiLayout->SetVisible(true);
  227. }
  228. else
  229. {
  230. pYouhuiLayout->SetVisible(false);
  231. }
  232. //再刷新打包费展示
  233. CLabelUI* pOtherPriceLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_otherprice")));
  234. if (dabao_money > 0)
  235. {
  236. std::wstring ws_dabaofei = L"打包费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(dabao_money, 2)) + L" 元";
  237. pOtherPriceLabel->SetText(ws_dabaofei.c_str());
  238. }
  239. else
  240. {
  241. pOtherPriceLabel->SetText(L"");
  242. }
  243. //再刷新总价展示
  244. CLabelUI* pTotalPrice = static_cast<CLabelUI*>(this->m_pm.FindControl(_T("diandan_page_totalprice")));
  245. pTotalPrice->SetText((L"总价:¥" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_price, 2))).c_str());
  246. }
  247. void CFupingWnd::UpdateShow(CZhengcanOrder& order, double total_youhui, double total_price, double dabao_money)
  248. {
  249. //先清空当前的显示
  250. CListUI* pList = static_cast<CListUI*>(m_pm.FindControl(_T("list_diandan_cart")));
  251. pList->RemoveAll();
  252. //然后依次渲染所有的
  253. int nItemNum = order.getItemNum();
  254. for (int i = 0; i < nItemNum; i++)
  255. {
  256. CZhengcanOrderItem item = order.getDiandanOrderItem(i);
  257. CDialogBuilder builder;
  258. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("diandan_cart_item.xml"), (UINT)0, NULL, &m_pm));
  259. pList->Add(pEle);
  260. if (item.m_is_taocan)
  261. {
  262. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  263. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  264. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  265. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  266. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  267. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  268. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  269. pEle->SetFixedHeight(84);
  270. pNature->SetVisible(true);
  271. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
  272. }
  273. else
  274. {
  275. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
  276. pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
  277. CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
  278. pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
  279. CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
  280. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
  281. CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
  282. if (item.is_nature)
  283. {
  284. pEle->SetFixedHeight(84);
  285. pNature->SetVisible(true);
  286. pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
  287. }
  288. else
  289. {
  290. pEle->SetFixedHeight(42);
  291. pNature->SetVisible(false);
  292. }
  293. }
  294. }
  295. //刷新优惠展示
  296. CHorizontalLayoutUI* pYouhuiLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi_layout")));
  297. CLabelUI* pYouhuiLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi")));
  298. if (total_youhui > 0)
  299. {
  300. wstring youhuilabel = L"已优惠 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_youhui, 2)) + L" 元";
  301. pYouhuiLabel->SetText(youhuilabel.c_str());
  302. pYouhuiLayout->SetVisible(true);
  303. }
  304. else
  305. {
  306. pYouhuiLayout->SetVisible(false);
  307. }
  308. //再刷新打包费展示
  309. CLabelUI* pOtherPriceLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_otherprice")));
  310. if (dabao_money > 0)
  311. {
  312. std::wstring ws_dabaofei = L"打包费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(dabao_money, 2)) + L" 元";
  313. pOtherPriceLabel->SetText(ws_dabaofei.c_str());
  314. }
  315. else
  316. {
  317. pOtherPriceLabel->SetText(L"");
  318. }
  319. //再刷新总价展示
  320. CLabelUI* pTotalPrice = static_cast<CLabelUI*>(this->m_pm.FindControl(_T("diandan_page_totalprice")));
  321. pTotalPrice->SetText((L"总价:¥" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_price, 2))).c_str());
  322. }
  323. void CFupingWnd::Stop()
  324. {
  325. m_is_work = false;
  326. }