WndBanner.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #include "CFrameWnd.h"
  2. void CFrameWnd::Thread_LoadedBanner(ThreadData threadData)
  3. {
  4. threadData.pFrame->GetBanner();
  5. threadData.pFrame->InitAsscessKey();
  6. }
  7. void CFrameWnd::GetBanner()
  8. {
  9. std::wstring tempPath = FolderCore::GetAppTempPath();
  10. banner->GetBannerlinkFromJson(tempPath);
  11. auto imgFilePath = tempPath + L"/" + std::to_wstring(0) + L".png";
  12. //获取图片
  13. for (size_t i = 0; i < banner->BannerCollection.size(); i++)
  14. {
  15. if (i <= BannerCore::ShowBannerCount)
  16. {
  17. char* ch = (LPSTR)(LPCTSTR)banner->BannerCollection[i].c_str();
  18. std::wstring wch = CharConvert::GetWideCharW(ch);
  19. imgFilePath = tempPath + L"/" + to_wstring(i) + L".png";
  20. bool isSuccess = banner->GetImage(wch, imgFilePath, i);
  21. if (banner->IsEmptyBanner == true && isSuccess == true)
  22. banner->IsEmptyBanner = false;
  23. }
  24. else
  25. {
  26. break;
  27. }
  28. //由于下载图片需要时间,优先下载第一张后,就显示该图片
  29. if (i == 0)
  30. {
  31. HBITMAP hBitmap = NULL;
  32. m_InstallingPage->pTabSwitch->RemoveAll();
  33. {
  34. imgFilePath = tempPath + L"/" + std::to_wstring(i) + L".png";
  35. CDuiString ImagePath(imgFilePath.c_str());
  36. CreateBannerUI(ImagePath, i);
  37. }
  38. m_InstallingPage->pTabSwitch->SelectItem(0);
  39. }
  40. }
  41. HBITMAP hBitmap = NULL;
  42. int count = 0;
  43. if (BannerCore::ShowBannerCount < banner->BannerCollection.size())
  44. {
  45. count = BannerCore::ShowBannerCount;
  46. }
  47. else
  48. {
  49. count = banner->BannerCollection.size();
  50. }
  51. for (size_t i = 1; i < count; i++)
  52. {
  53. imgFilePath = tempPath + L"/" + std::to_wstring(i) + L".png";
  54. CDuiString ImagePath(imgFilePath.c_str());
  55. CreateBannerUI(ImagePath, i);
  56. }
  57. }
  58. void CFrameWnd::CreateBannerUI(CDuiString ImagePath, int i)
  59. {
  60. std::wstring ss = L"Banner" + std::to_wstring(i);
  61. CControlUI* tem = new CControlUI();
  62. tem->SetName(ss.c_str());
  63. tem->SetFixedWidth(XML_BannerWidth);
  64. tem->SetFixedHeight(XML_BannerHeight);
  65. tem->SetMinWidth(XML_BannerWidth);
  66. tem->SetMaxHeight(XML_BannerHeight);
  67. m_pm.RemoveImage(ImagePath);
  68. m_pm.AddImage(ImagePath);
  69. tem->SetBkImage(ImagePath);
  70. m_InstallingPage->pTabSwitch->Add(tem);
  71. }
  72. void CFrameWnd::SetTimerBanner()
  73. {
  74. bool m_bOnline = NetWorkState::IsNetWorking();
  75. if (m_bOnline)
  76. {
  77. KillAllTimer();
  78. StartTimer(Timer_Banner_ID);
  79. StartTimer(Timer_Installing_ID);
  80. CFrameWnd::m_SilenceInstallingType = SilenceInstallingType::DownLoading;
  81. m_InstallingPage->NetWorkUI(m_bOnline);
  82. if (banner->BannerCollection.size() == 0)
  83. GetBanner();
  84. thread installingThread(Thread_Installing, m_threadData);
  85. installingThread.detach();
  86. }
  87. }
  88. void CFrameWnd::SetTimerBannerSwitch()
  89. {
  90. currentImageNum++;
  91. currentImageNum = currentImageNum >= BannerCore::ShowBannerCount ? 0 : currentImageNum;
  92. m_InstallingPage->pTabSwitch->SelectItem(currentImageNum);
  93. }
  94. void CFrameWnd::WaitForNetwork()
  95. {
  96. KillAllTimer();
  97. StartTimer(Timer_WaitForNetwork_ID);
  98. }