mfc cef

本文详细介绍了如何在MFC单文档应用程序中集成CEF(Chromium Embedded Framework),包括初始化CEF、创建浏览器窗口、加载资源文件、处理自定义协议、C++与JS交互以及自定义标题栏的方法。通过这些步骤,可以实现在MFC应用中嵌入Web页面并进行交互操作。
摘要由CSDN通过智能技术生成
在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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值