{LOG_TRACE(L"登录系统未完成,程序关闭。");returnFALSE;}//Tocreatethemainwindow,thiscodecreatesanewframewindow//objectandthensetsitastheapplication'smainwindowobjectCMainFrame*main_frm=newCMainFrame;if(!main_frm){LOG_ERROR(L"系统内存不足!创建CMainFrame对象失败,程序关闭。");returnFALSE;}m_pMainWnd=main_frm;//createandloadtheframewithitsresourcesmain_frm->LoadFrame(IDR_MAINFRAME,WS_OVERLAPPEDWINDOW|FWS_ADDTOTITLE,NULL,NULL);//Thenlaunchthemainwindow.if(!main_frm->Launch()){LOG_ERROR(L"主窗口启动失败,程序关闭。");returnFALSE;}//Theoneandonlywindowhasbeeninitialized,soshowandupdateitmain_frm->ShowWindow(SW_SHOWMAXIMIZED);main_frm->UpdateWindow();returnTRUE;}intCETradeClientApp::ExitInstance(){if(m_cef_initialized){//closingstopworkloopm_cef_initialized=false;//releaseCEFappm_browser_app=nullptr;//shutdownCEFCefShutdown();}AfxOleTerm(FALSE);m_instance_mgr.Unregister();returnCWinApp::ExitInstance();}//BOOLCETradeClientApp::PumpMessage()//{//if(m_cef_initialized)//CefDoMessageLoopWork();//Integratewithanexistingapplicationmessageloopinsteadofrunningitsownmessageloop//returnCWinApp::PumpMessage();//}boolCETradeClientApp::InitializeCef(){void*sandbox_info=NULL;#ifCEF_ENABLE_SANDBOX//Managethelifespanofthesandboxinformationobject.Thisisnecessary//forsandboxsupportonWindows.Seecef_sandbox_win.hforcompletedetails.CefScopedSandboxInfoscoped_sandbox;sandbox_info=scoped_sandbox.sandbox_info();#endifm_browser_app=newBrowserApp();CefMainArgsmain_args(GetModuleHandle(NULL));//getarguments//Executethesecondaryprocess,ifany.intexit_code=CefExecuteProcess(main_args,m_browser_app.get(),NULL);if(exit_code>=0)returnfalse;//Indicatetheinitializationisdoneandshouldnotcontinuetonextstep.namespacefs=boost::filesystem;wchar_texe_path[MAX_PATH];HMODULEh_module=GetModuleHandle(NULL);if(NULL!=h_module)GetModuleFileName(h_module,exe_path,sizeof(exe_path));elsethrowstd::exception("Calling windows API to get exe path failed.");std::stringexe_path_=wstr_2_str(fs::wpath(exe_path).parent_path().wstring());//setupsettingsCefSettingssettings;settings.command_line_args_disabled=true;//Won'tacceptcommandlineargument.settings.multi_threaded_message_loop=true;//Settotruetohavethebrowserprocessmessageloopruninaseparatethread.CefString(&settings.log_file)=exe_path_+"\\cef\\cef.log";CefString(&settings.resources_dir_path)=exe_path_+"\\cef\\Resources";//WARNING:'resources_dir_path'hastobeabsoulutepath.CefString(&settings.locales_dir_path)=exe_path_+"\\cef\\Resources\\locales";//不使用缓存,避免在某些环境下,cef无法使用缓存路径下的数据,造成页面无法显示,注意:如果缓存路径设置为空,将不支持HTML5LocalStorage。CefString(&settings.cache_path)="";returnCefInitialize(main_args,settings,m_browser_app.get(),sandbox_info);//@}}//CAboutDlgdialogusedforAppAboutclassCAboutDlg:publicCDialogEx{public:CAboutDlg();//DialogDataenum{IDD=IDD_ABOUTBOX};protected:virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport//Implementationprotected:DECLARE_MESSAGE_MAP()};CAboutDlg::CAboutDlg():CDialogEx(CAboutDlg::IDD){}voidCAboutDlg::DoDataExchange(CDataExchange*pDX){CDialogEx::DoDataExchange(pDX);}BEGIN_MESSAGE_MAP(CAboutDlg,CDialogEx)END_MESSAGE_MAP()//AppcommandtorunthedialogvoidCETradeClientApp::OnAppAbout(){CAboutDlgaboutDlg;aboutDlg.DoModal();}//CETradeClientAppmessagehandlers//InstanceManagerCETradeClientApp::InstanceManager::InstanceManager():m_mutex_handle(nullptr){}CETradeClientApp::InstanceManager::~InstanceManager(){Unregister();}boolCETradeClientApp::InstanceManager::Register(conststd::wstring&app_id){HANDLEhHandle=CreateMutex(NULL,TRUE,app_id.c_str());if(ERROR_ALREADY_EXISTS==GetLastError()){//Logreturnfalse;}m_mutex_handle=hHandle;returntrue;}voidCETradeClientApp::InstanceManager::Unregister(){if(nullptr!=m_mutex_handle){ReleaseMutex(m_mutex_handle);//ExplicitlyreleasemutexCloseHandle(m_mutex_handle);//closehandlebeforeterminatingm_mutex_handle=nullptr;}}