| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399 |
- #include "../pch/pch.h"
- #include "CFupingWnd.h"
- #include "../page/CDiandanPageUI.h"
- LRESULT CFupingWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- POINT pt;
- pt.x = GET_X_LPARAM(lParam);
- pt.y = GET_Y_LPARAM(lParam);
- ::ScreenToClient(*this, &pt);
- RECT rcClient;
- ::GetClientRect(*this, &rcClient);
- RECT rcCaption = m_pm.GetCaptionRect();
- if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
- && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
- {
- CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
- if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
- {
- return HTCAPTION;
- }
- }
- return HTCLIENT;
- }
- LRESULT CFupingWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- SIZE szRoundCorner = m_pm.GetRoundCorner();
- if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
- {
- CDuiRect rcWnd;
- ::GetWindowRect(*this, &rcWnd);
- rcWnd.Offset(-rcWnd.left, -rcWnd.top);
- rcWnd.right++;
- rcWnd.bottom++;
- HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
- ::SetWindowRgn(*this, hRgn, TRUE);
- ::DeleteObject(hRgn);
- }
- bHandled = FALSE;
- return 0;
- }
- LRESULT CFupingWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- LRESULT lRes = 0;
- BOOL bHandled = TRUE;
- switch (uMsg)
- {
- case WM_CREATE:
- lRes = OnCreate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCACTIVATE:
- lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCCALCSIZE:
- lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCPAINT:
- lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
- break;
- case WM_NCHITTEST:
- lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
- break;
- case WM_SIZE:
- lRes = OnSize(uMsg, wParam, lParam, bHandled);
- break;
- default:
- bHandled = FALSE;
- }
- if (bHandled)
- {
- return lRes;
- }
- if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
- {
- return lRes;
- }
- return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
- }
- LRESULT CFupingWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
- {
- if (uMsg == WM_KEYDOWN)
- {
- if (wParam == VK_RETURN)
- {
- return true;
- }
- else if (wParam == VK_ESCAPE)
- {
- Close(IDCANCEL);
- return true;
- }
- }
- return false;
- }
- LRESULT CFupingWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
- {
- LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
- styleValue &= ~WS_CAPTION;
- ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
- // 把自己的窗口句柄与窗口绘制管理器挂接在一起
- m_pm.Init(m_hWnd);
- m_pm.AddPreMessageFilter(this);
- CDialogBuilder builder;
- CControlUI* pRoot = builder.Create(_T("fuping_wnd.xml"), (UINT)0, NULL, &m_pm);
- ASSERT(pRoot && "Failed to parse XML");
- // 把这些控件绘制到本窗口上
- m_pm.AttachDialog(pRoot);
- // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
- m_pm.AddNotifier(this);
- Init();
- return 0;
- }
- void CFupingWnd::Notify(TNotifyUI& msg)
- {
-
- }
- //刚启动程序初始化副屏窗口的时候执行,app生命周期只执行一次
- void CFupingWnd::Init()
- {
- m_is_work = true;
- //启动轮播图展示任务
- std::thread(&CFupingWnd::HandleFupingImage, this).detach();
- }
- void CFupingWnd::HandleFupingImage()
- {
- while (m_is_work == true)
- {
- if (CShopinfo::GetInstance()->m_shop_name.size() == 0)
- {
- //还没登录成功,没拿到店铺名字,等待
- CSystem::my_sleep(1);
- continue;
- }
- //更新店铺名字
- CLabelUI* nameControl = static_cast<CLabelUI*>(m_pm.FindControl(L"shopname"));
- std::wstring shopname = CLewaimaiString::UTF8ToUnicode(CShopinfo::GetInstance()->m_shop_name);
- nameControl->SetText(shopname.c_str());
- std::vector<std::wstring> lunbo_img_paths = CShopinfo::GetInstance()->m_lunbo_img_paths;
- if (lunbo_img_paths.size() == 0)
- {
- //有可能后台没设置轮播图,有可能还没请求到后台最新数据,等待
- CSystem::my_sleep(2);
- continue;
- }
- //然后开始处理轮播图
- if (m_curImageNum > lunbo_img_paths.size() - 1)
- {
- m_curImageNum = 0;
- }
- std::wstring image_path = lunbo_img_paths[m_curImageNum];
- //判断图片是否存在
- if (!CSystem::IsFileExist(image_path))
- {
- //轮播图的图片还未下载好
- CSystem::my_sleep(3);
- //3秒后还没下载好,处理下一张
- m_curImageNum++;
- continue;
- }
- //轮播图的图片已经下载好了,那么就直接渲染
- CControlUI* imageControl = static_cast<CControlUI*>(m_pm.FindControl(L"lunbo_image"));
- imageControl->SetBkImage(image_path.c_str());
- //等待3秒钟,换下一张
- CSystem::my_sleep(3);
- //3秒轮播一次
- m_curImageNum++;
- continue;
- }
- //这个线程结束后,释放自己
- delete this;
- }
- //刷新副屏显示
- void CFupingWnd::UpdateShow(CDiandanOrder& order, double total_youhui, double total_price, double dabao_money)
- {
- //先清空当前的显示
- CListUI* pList = static_cast<CListUI*>(m_pm.FindControl(_T("list_diandan_cart")));
- pList->RemoveAll();
- //然后依次渲染所有的
- int nItemNum = order.getItemNum();
- for (int i = 0; i < nItemNum; i++)
- {
- CDiandanOrderItem item = order.getDiandanOrderItem(i);
- CDialogBuilder builder;
- CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("diandan_cart_item.xml"), (UINT)0, NULL, &m_pm));
- pList->Add(pEle);
- if (item.m_is_taocan)
- {
- CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
- pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
- CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
- pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
- CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
- pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
- CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
- pEle->SetFixedHeight(84);
- pNature->SetVisible(true);
- pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
- }
- else
- {
- CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
- pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
- CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
- pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
- CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
- pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
- CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
- if (item.is_nature)
- {
- pEle->SetFixedHeight(84);
- pNature->SetVisible(true);
- pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
- }
- else
- {
- pEle->SetFixedHeight(42);
- pNature->SetVisible(false);
- }
- }
- }
- //刷新优惠展示
- CHorizontalLayoutUI* pYouhuiLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi_layout")));
- CLabelUI* pYouhuiLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi")));
- if (total_youhui > 0)
- {
- wstring youhuilabel = L"已优惠 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_youhui, 2)) + L" 元";
- pYouhuiLabel->SetText(youhuilabel.c_str());
- pYouhuiLayout->SetVisible(true);
- }
- else
- {
- pYouhuiLayout->SetVisible(false);
- }
- //再刷新打包费展示
- CLabelUI* pOtherPriceLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_otherprice")));
- if (dabao_money > 0)
- {
- std::wstring ws_dabaofei = L"打包费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(dabao_money, 2)) + L" 元";
- pOtherPriceLabel->SetText(ws_dabaofei.c_str());
- }
- else
- {
- pOtherPriceLabel->SetText(L"");
- }
- //再刷新总价展示
- CLabelUI* pTotalPrice = static_cast<CLabelUI*>(this->m_pm.FindControl(_T("diandan_page_totalprice")));
- pTotalPrice->SetText((L"总价:¥" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_price, 2))).c_str());
- }
- void CFupingWnd::UpdateShow(CZhengcanOrder& order, double total_youhui, double total_price, double dabao_money)
- {
- //先清空当前的显示
- CListUI* pList = static_cast<CListUI*>(m_pm.FindControl(_T("list_diandan_cart")));
- pList->RemoveAll();
- //然后依次渲染所有的
- int nItemNum = order.getItemNum();
- for (int i = 0; i < nItemNum; i++)
- {
- CZhengcanOrderItem item = order.getDiandanOrderItem(i);
- CDialogBuilder builder;
- CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("diandan_cart_item.xml"), (UINT)0, NULL, &m_pm));
- pList->Add(pEle);
- if (item.m_is_taocan)
- {
- CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
- pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
- CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
- pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
- CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
- pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
- CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
- pEle->SetFixedHeight(84);
- pNature->SetVisible(true);
- pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
- }
- else
- {
- CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_name")));
- pName->SetText(CLewaimaiString::UTF8ToUnicode(item.getNameShow()).c_str());
- CLabelUI* pNum = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_num")));
- pNum->SetText(CLewaimaiString::UTF8ToUnicode(item.num).c_str());
- CLabelUI* pPrice = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_price")));
- pPrice->SetText(CLewaimaiString::UTF8ToUnicode(item.show_price).c_str());
- CLabelUI* pNature = static_cast<CLabelUI*>(pEle->FindSubControl(_T("diandan_cart_item_nature")));
- if (item.is_nature)
- {
- pEle->SetFixedHeight(84);
- pNature->SetVisible(true);
- pNature->SetText(CLewaimaiString::UTF8ToUnicode(item.getNatureShow()).c_str());
- }
- else
- {
- pEle->SetFixedHeight(42);
- pNature->SetVisible(false);
- }
- }
- }
- //刷新优惠展示
- CHorizontalLayoutUI* pYouhuiLayout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi_layout")));
- CLabelUI* pYouhuiLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_youhui_tishi")));
- if (total_youhui > 0)
- {
- wstring youhuilabel = L"已优惠 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_youhui, 2)) + L" 元";
- pYouhuiLabel->SetText(youhuilabel.c_str());
- pYouhuiLayout->SetVisible(true);
- }
- else
- {
- pYouhuiLayout->SetVisible(false);
- }
- //再刷新打包费展示
- CLabelUI* pOtherPriceLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("diandan_page_otherprice")));
- if (dabao_money > 0)
- {
- std::wstring ws_dabaofei = L"打包费 " + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(dabao_money, 2)) + L" 元";
- pOtherPriceLabel->SetText(ws_dabaofei.c_str());
- }
- else
- {
- pOtherPriceLabel->SetText(L"");
- }
- //再刷新总价展示
- CLabelUI* pTotalPrice = static_cast<CLabelUI*>(this->m_pm.FindControl(_T("diandan_page_totalprice")));
- pTotalPrice->SetText((L"总价:¥" + CLewaimaiString::UTF8ToUnicode(CLewaimaiString::DoubleToString(total_price, 2))).c_str());
- }
- void CFupingWnd::Stop()
- {
- m_is_work = false;
- }
|