全局变量:
CefRefPtr<ClientApp> CefApp=NULL;
重写MFC启动代码:
//添加以下代码,开始
CefMainArgs main_args;//(hInstance);
CefApp = new ClientApp();
// Execute the secondary process, if any.
int exit_code = CefExecuteProcess(main_args, CefApp.get(), NULL);
if (exit_code >= 0)
return exit_code;
// Parse command line arguments. The passed in values are ignored on Windows.
// AppInitCommandLine(0, NULL);
CefSettings settings;
settings.multi_threaded_message_loop=true;
//settings
// Populate the settings based on command line arguments.
// AppGetSettings(settings);
// Initialize CEF.
if(!CefInitialize(main_args, settings, CefApp.get(), NULL))
{
ASSERT(0);
}
//结束
CWinThread *pThread = AfxGetThread();//获取主线程指针
CWinApp *pApp = AfxGetApp();
AfxWinInit();
....
pApp->InitApplication();
...
pThread->InitInstance();//初始化应用程序实例
...
nReturnCode = pThread->Run();//开始消息循环
CefShutdown();
return nReturnCode;
}
在MFC中void CMainFrame::OnClose()添加以下代码
1
|
::DestroyWindow(hMessageWnd);
|