CFrameWndInit.cpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. #include "CFrameWnd.h"
  2. //说明:初始化窗口,但对运行的程序不常操作
  3. #pragma region 初始化
  4. SilenceInstallingType CFrameWnd::m_SilenceInstallingType = SilenceInstallingType::None;
  5. CFrameWnd::CFrameWnd(LPCTSTR pszXMLPath)
  6. : m_strXMLPath(pszXMLPath)
  7. {
  8. }
  9. CFrameWnd::CFrameWnd()
  10. {
  11. m_MainPage.SetPaintMagager(&m_pm);
  12. AddVirtualWnd(_T("MainWnd"), &m_MainPage);
  13. banner = new CAdsBanner();
  14. m_threadData.pFrame = this;
  15. }
  16. CFrameWnd::~CFrameWnd(void)
  17. {
  18. RemoveVirtualWnd(_T("MainWnd"));
  19. }
  20. LPCTSTR CFrameWnd::GetWindowClassName() const
  21. {
  22. return _T("MainWnd");
  23. }
  24. CDuiString CFrameWnd::GetSkinFolder()
  25. {
  26. return _T("");
  27. }
  28. void CFrameWnd::InitControls()
  29. {
  30. m_InstallationPage = new InstallationPage(&m_pm);
  31. m_InstallingPage = new InstallingPage(&m_pm);
  32. m_InstalledPage = new InstalledPage(&m_pm);
  33. InitHomeControls();
  34. InitInstallingControls();
  35. InitInstalledControls();
  36. }
  37. void CFrameWnd::InitAsscessKey()
  38. {
  39. ComparVersion comparVersion;
  40. VertionResultType state = comparVersion.GetProductInfo(Product::smName_Product, Product::URI_AppXml);
  41. }
  42. void CFrameWnd::InitWindow()
  43. {
  44. SetIcon(IDI_ICON1);
  45. SetWindowLong(m_hWnd, GWL_STYLE, GetWindowLong(m_hWnd, GWL_STYLE) & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME);//禁止最大化窗口
  46. this->CenterWindow();
  47. InitControls();
  48. //AdaptationDPI();
  49. SelectLayout(LayoutType::Home);
  50. ShowWindow();
  51. //MessageBoxWnd::Show(m_hWnd, MessageContentType::InstalledIsExitApp);
  52. }
  53. void CFrameWnd::AdaptationDPI()
  54. {
  55. HWND hd = FindWindow(L"Progman", L"Program Manager");
  56. int dpiValue = GetDpiForWindow(hd);//当前DPI
  57. double currentZoom = dpiValue / 96.0;//当前显示比例
  58. double tempDPI = currentZoom;
  59. int dpiOffer = (int)(96 - (currentZoom - 1) * 96.0);//DPI偏移量
  60. if (dpiValue == 96)
  61. {
  62. dpi = 1;
  63. CurrentDPI = 96;
  64. }
  65. else
  66. {
  67. dpi = dpiOffer / 96.0;//比例偏移量
  68. CurrentDPI = 96 - dpiOffer;
  69. dpi = 1 - dpi;
  70. }
  71. //m_pm.SetDPI(CurrentDPI);
  72. }
  73. void CFrameWnd::setDPI(int DPI)
  74. {
  75. //m_pm.SetDPI(DPI);
  76. }
  77. //使用OnCreate就会不触发GetSkinFile事件
  78. //LRESULT CFrameWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  79. //{
  80. //
  81. // return 1;
  82. //}
  83. LRESULT CFrameWnd::OnDPIChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  84. {
  85. m_pm.SetDPI(LOWORD(wParam));
  86. m_pm.ResetDPIAssets();
  87. int g_dpi = HIWORD(wParam);
  88. RECT* const prcNewWindow = (RECT*)lParam;
  89. SetWindowPos(m_hWnd,
  90. NULL,
  91. prcNewWindow->left,
  92. prcNewWindow->top,
  93. prcNewWindow->right - prcNewWindow->left,
  94. prcNewWindow->bottom - prcNewWindow->top,
  95. SWP_NOZORDER | SWP_NOACTIVATE);
  96. if (m_pm.GetRoot() != NULL) m_pm.GetRoot()->NeedUpdate();
  97. bHandled = false;
  98. wstring optionName;
  99. wstringstream wss;
  100. wss << L"DPI";
  101. wss << m_pm.GetDPIObj()->GetDPI();
  102. wss >> optionName;
  103. COptionUI* option = static_cast<COptionUI*>(m_pm.FindControl(optionName.c_str()));
  104. option->Selected(true);
  105. return 0;
  106. }
  107. LRESULT CFrameWnd::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  108. {
  109. LRESULT lRes = 0;
  110. switch (uMsg)
  111. {
  112. case WM_CREATE:break;
  113. case WM_DESTROY:
  114. {
  115. ::PostQuitMessage(0);
  116. //清除缓存文件(缓存文件夹InstallTemp,Install包含Banner图片,xml产品信息,config.ini等)
  117. //安装包
  118. FolderCore::ClearAllTempFolder();
  119. break;
  120. }
  121. case WM_NCCALCSIZE:
  122. return 0;
  123. /*case WM_DPICHANGED:
  124. lRes = OnDPIChanged(uMsg, wParam, lParam, bHandled);
  125. break;*/
  126. case WM_TIMER:
  127. lRes = OnTimer(uMsg, wParam, lParam, bHandled);
  128. break;
  129. case WM_KEYDOWN:
  130. lRes = OnKeyDown(uMsg, wParam, lParam, bHandled);
  131. default:
  132. break;
  133. }
  134. return lRes;
  135. //以下代码的实现,会导致编辑框失去焦点之后而无法再次获取焦点
  136. /*if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes)) return lRes;
  137. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);*/
  138. }
  139. LRESULT CFrameWnd::OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  140. {
  141. switch (wParam)
  142. {
  143. case _T('A'):
  144. {
  145. if (GetKeyState(VK_CONTROL) < 0)
  146. {
  147. if (m_InstallationPage->EdFilepath->IsFocused())
  148. {
  149. m_InstallationPage->EdFilepath->SetSelAll();
  150. }
  151. }
  152. }
  153. case _T('C'):
  154. {
  155. if (GetKeyState(VK_CONTROL) < 0)
  156. {
  157. if (m_InstallationPage->EdFilepath->IsFocused() &&
  158. m_InstallationPage->EdFilepath->GetSelText() == m_InstallationPage->EdFilepath->GetText())
  159. {
  160. m_InstallationPage->EdFilepath->Copy();
  161. }
  162. }
  163. }
  164. break;
  165. }
  166. return 0;
  167. }
  168. void CFrameWnd::Notify(TNotifyUI& msg)
  169. {
  170. SlotMsg(msg);
  171. LayoutNotify(msg);
  172. return WindowImplBase::Notify(msg);
  173. }
  174. void CFrameWnd::LayoutNotify(TNotifyUI& msg)
  175. {
  176. switch (m_State.m_LayoutType)
  177. {
  178. case LayoutType::Home:
  179. NotifyHome(msg);
  180. break;
  181. case LayoutType::Installing:
  182. NotifyInstalling(msg);
  183. break;
  184. case LayoutType::Installed:
  185. NotifyInstalled(msg);
  186. break;
  187. default:
  188. break;
  189. }
  190. }
  191. #pragma endregion
  192. //自定义安装,收缩展开窗口大小
  193. void CFrameWnd::CustomInstallWndSize(bool isExpend)
  194. {
  195. try
  196. {
  197. if (isExpend)
  198. {
  199. std::wstring textcontent = CLanguage::GetText(TextType::Btn_CutomInstall);
  200. m_InstallationPage->CheckInstallSetting->SetText(textcontent.c_str());
  201. m_InstallationPage->Lbicon->SetText(L"▲");
  202. ::GetClientRect(*this, &start_rect_);
  203. SetWindowPos(m_hWnd, NULL, 0, 0, XML_WndExpendWidth * dpi, XML_WndExpenHeight * dpi, SWP_NOMOVE);
  204. ischeckCustom = true;
  205. }
  206. else
  207. {
  208. std::wstring textcontent = CLanguage::GetText(TextType::Btn_CutomInstall);
  209. m_InstallationPage->Lbicon->SetText(L"▼");
  210. m_InstallationPage->CheckInstallSetting->SetText(textcontent.c_str());
  211. ::GetClientRect(*this, &start_rect_);
  212. SetWindowPos(m_hWnd, NULL, 0, 0, XML_WndWidth * dpi, XML_WndHeight * dpi, SWP_NOMOVE);
  213. ischeckCustom = false;
  214. }
  215. }
  216. catch (exception ex)
  217. {
  218. }
  219. //刚开始点击自定义安装会崩溃
  220. //m_pm.SetDPI(CurrentDPI);
  221. }
  222. //if (msg.sType == _T("link"))
  223. //{
  224. // if (control == UI_TextShowContentLink)
  225. // {
  226. // DuiLib::CTextUI* pText = (DuiLib::CTextUI*)msg.pSender;
  227. // int index = (msg.wParam == 0 ? 0 : 1);
  228. // DuiLib::CDuiString* str = pText->GetLinkContent(index);
  229. // ShellExecute(NULL, _T("open"), str->GetData(), NULL, NULL, SW_SHOWNORMAL);
  230. // }
  231. //}