在mfc单文档程序中加入cef:
1.在BOOL CtestCEFApp::InitInstance()中初始化cef
HINSTANCE hInst = GetModuleHandle(NULL);
CefMainArgs main_args(hInst);
m_cefApp = new ClientApp();
//cef默认启动四个进程,分别是浏览器主进程,渲染进程,GPU进程,插件进程,如果不是主进程则直接退出
//AfxMessageBox(L"CefExecuteProcess");
int exit_code = CefExecuteProcess(main_args, m_cefApp.get(), NULL);
if (exit_code >= 0)
return exit_code;
//设置cef参数
CString szCEFCache;
CString szPath;
INT nLen = GetTempPath( 0, NULL ) + 1;
GetTempPath( nLen, szPath.GetBuffer( nLen ));
szCEFCache.Format( _T("%scache\0\0"), szPath );
CefSettings settings;
//settings.no_sandbox = TRUE;
//settings.multi_threaded_message_loop = FALSE;
CefString(&settings.cache_path) = szCEFCache;
//CefSettingsTraits::init( &cSettings);
//cSettings.multi_threaded_message_loop = false;
m_bCEFInitialized = CefInitialize(main_args, settings,m_cefApp.get(), NULL);
//初始化自定义协议
scheme_test::InitTest();
2.创建浏览器窗口
BOOL ClientApp::CreateBrowser(HWND hWnd, CRect rect, LPCTSTR pszURL)
{
CefBrowserSettings settings;
CefWindowInfo info;
info.SetAsChild( hWnd, rect );
std::string url = "test://test/html1.html";
return CefBrowserHost::CreateBrowser( info, m_cefHandler.get(), url, settings, NULL );
}
3.资源文件加载
namespace scheme_test {
// Implementation of the factory for for creating schema handlers.
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
// Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser>
1.在BOOL CtestCEFApp::InitInstance()中初始化cef
HINSTANCE hInst = GetModuleHandle(NULL);
CefMainArgs main_args(hInst);
m_cefApp = new ClientApp();
//cef默认启动四个进程,分别是浏览器主进程,渲染进程,GPU进程,插件进程,如果不是主进程则直接退出
//AfxMessageBox(L"CefExecuteProcess");
int exit_code = CefExecuteProcess(main_args, m_cefApp.get(), NULL);
if (exit_code >= 0)
return exit_code;
//设置cef参数
CString szCEFCache;
CString szPath;
INT nLen = GetTempPath( 0, NULL ) + 1;
GetTempPath( nLen, szPath.GetBuffer( nLen ));
szCEFCache.Format( _T("%scache\0\0"), szPath );
CefSettings settings;
//settings.no_sandbox = TRUE;
//settings.multi_threaded_message_loop = FALSE;
CefString(&settings.cache_path) = szCEFCache;
//CefSettingsTraits::init( &cSettings);
//cSettings.multi_threaded_message_loop = false;
m_bCEFInitialized = CefInitialize(main_args, settings,m_cefApp.get(), NULL);
//初始化自定义协议
scheme_test::InitTest();
2.创建浏览器窗口
BOOL ClientApp::CreateBrowser(HWND hWnd, CRect rect, LPCTSTR pszURL)
{
CefBrowserSettings settings;
CefWindowInfo info;
info.SetAsChild( hWnd, rect );
std::string url = "test://test/html1.html";
return CefBrowserHost::CreateBrowser( info, m_cefHandler.get(), url, settings, NULL );
}
3.资源文件加载
namespace scheme_test {
// Implementation of the factory for for creating schema handlers.
class ClientSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
// Return a new scheme handler instance to handle the request.
virtual CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser>