#pragma once
//核心
#include "CDownLoadFile.h"
#include "CCmd.h"
//字符与通用
#include "CLanguage.h"
#include "CClasses.h"
#include "DefineStr.h"
//系统与资源
#include <WinInet.h>//网络
#include <thread>
#include "resource.h"
//UI
#include "CMsgWnd.h"
//#include "CAdsBanner.h"
#include "InstallPage.h"
#include "InstallingPage.h"
#include "InstalledPage.h"
#include "MessageBoxWnd.h"
#include "CMainPage.h"
#include "stdafx.h"
//#include "duilib.h"
#include "KeyVar.h"
#include "FileCore.h"
#include "ComparVersion.h"
#include "CharConvert.h"
 class CFrameWnd : public WindowImplBase
{

#pragma region 全局

private:
	CDuiString	m_strXMLPath;
	ThreadData m_threadData;
	CurrentState m_State;
	static SilenceInstallingType m_SilenceInstallingType;
	int CurrentDPI = 96;
	double dpi = 1;
	RECT start_rect_;
	
	CMainPage m_MainPage;
	bool IsNeedReStartSystem = false;//是否需要重启系统(win8 Net安装之后需要重启)
public:
	//初始化
	 explicit CFrameWnd(LPCTSTR pszXMLPath);
	 CFrameWnd();
	 ~CFrameWnd(void);
	 virtual LPCTSTR GetWindowClassName() const;
	 virtual CDuiString GetSkinFile() { return  XML_MainFile; }
	 virtual CDuiString GetSkinFolder();
	 void InitControls();
	 void InitWindow();
	 void InitAsscessKey();
	 void KillAllTimer();
	 void StartTimer(UINT_PTR ID);
private:
	 void CustomInstallWndSize(bool isExpend);
	 //逻辑
	 void setDPI(int DPI);
	 void AdaptationDPI();
	 void SelectLayout(LayoutType LayoutType);
	 void SlotMsg(TNotifyUI& msg);
	 void LayoutNotify(TNotifyUI& msg);
	 //消息事件
	 void Notify(TNotifyUI& msg);
	// LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	 LRESULT OnDPIChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	 LRESULT HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	 LRESULT OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	 bool isclose = false;
	 LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	 LRESULT OnKeyDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
#pragma endregion


#pragma region Banner事件和变量
private:
	CAdsBanner* banner;
	int currentImageNum = 0;
public:
	void GetBanner();
	void CreateBannerUI(CDuiString ImagePath, int i);
	void SetTimerBanner();
	void SetTimerBannerSwitch();
	void WaitForNetwork();
	static void Thread_LoadedBanner( ThreadData threadData);
#pragma endregion

#pragma region 安装主页
public:
	bool m_isCanInstall = false;//有没有满足条件安装
	
private:
	InstallationPage* m_InstallationPage;
	bool ischeckCustom = false;
	//初始化
	void InitHomeControls();
	//逻辑
	bool GetVersionState();
	void SetSelectedFolder();
	void GoToLink(std::wstring linkStr);
	void Install_Click();
	static void Thread_GetVerstion(ThreadData threadData);

	//消息事件
	void NotifyHome(TNotifyUI& msg);
	LRESULT HomeMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	
#pragma endregion


#pragma region 安装中
private:
	InstallingPage* m_InstallingPage;
	void InitInstallingControls();
	void SetTimerInstalling();
	void SetTimerSilen();
	static void Thread_Installing(ThreadData threadData);
	//消息事件
	void NotifyInstalling(TNotifyUI& msg);
	LRESULT InstallingMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	
#pragma endregion

#pragma region 安装完成
private:
	InstalledPage* m_InstalledPage;
	void InitInstalledControls();
	void ReStartSystem();
	void OpenApp_Click();
	static void Thread_OpenApp(ThreadData threadData);
	//消息事件
	void NotifyInstalled(TNotifyUI& msg);
	LRESULT InstalledMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
#pragma endregion


};
