#include "stdafx.h"
#include "duilib.h"
#include "CFrameWnd.h"
#include "CSystemInfo.h"

CFrameWnd* CreateFrameWnd(HINSTANCE hInstance)
{
	CFrameWnd* pFrame = new CFrameWnd();
	if (pFrame == NULL) return NULL;

	pFrame->Create(NULL, _T("MainWnd"), UI_WNDSTYLE_FRAME, 0);
	pFrame->InitWindow();

	return pFrame;
}

//加载XML文件界面资源、记录程序运行配置信息
bool LoadedResources(HINSTANCE hInstance)
{	//判断是否存在同一个exe；
	if (CSystemInfo::IsHanvedCurrentWindow() == true) return false;

	HRESULT Hr = ::CoInitialize(NULL);
	if (FAILED(Hr))
		return false;

	CPaintManagerUI::SetInstance(hInstance);
	CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
	CFrameWnd* pFrame = CreateFrameWnd(hInstance);

	if (pFrame == NULL)
		return false;

	CSystemInfo::isWriteAppProcessInfoToIni(pFrame->GetHWND());
	CPaintManagerUI::MessageLoop();

	return true;
}


int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR /*lpCmdLine*/, int nCmdShow)
{

	FolderCore::InitAppTempPath();
	// 初始化UI管理器
	if (LoadedResources(hInstance) == false)
		return 0;
	::CoUninitialize();//等待程序结束后，释放资源

	return 0;
}

