MFC嵌入浏览器框架CEF
2016-05-23 19:51
357 查看
MFC嵌入浏览器框架CEF
flyfish
环境 win7,VC2013 update5
APP头文件
APP实现文件
APP构造函数
APP初始化函数
退出函数
重写函数
对话框初始化函数
//加载其他网页时调用
下载地址
flyfish
环境 win7,VC2013 update5
APP头文件
BOOL m_bCEFInitialized;//是否初始化 CefRefPtr<ClientApp> m_cefApp;
APP实现文件
APP构造函数
CXApp::CXApp() { m_bCEFInitialized = FALSE; }
APP初始化函数
BOOL CXApp::InitInstance() { m_cefApp = new ClientApp(); // get arguments CefMainArgs main_args(GetModuleHandle(NULL)); // Execute the secondary process, if any. int exit_code = CefExecuteProcess(main_args, m_cefApp.get(), NULL); if (exit_code >= 0) return exit_code; CefSettings settings; settings.no_sandbox = TRUE; //CefString(&settings.cache_path) = szCEFCache; void* sandbox_info = NULL; #if CEF_ENABLE_SANDBOX // Manage the life span of the sandbox information object. This is necessary // for sandbox support on Windows. See cef_sandbox_win.h for complete details. CefScopedSandboxInfo scoped_sandbox; sandbox_info = scoped_sandbox.sandbox_info(); #endif //CEF Initiaized m_bCEFInitialized = CefInitialize(main_args, settings, m_cefApp.get(), sandbox_info); }
退出函数
int CXApp::ExitInstance() { // shutdown CEF if (m_bCEFInitialized) { // closing stop work loop m_bCEFInitialized = FALSE; // release CEF app m_cefApp = NULL; // shutdown CEF CefShutdown(); } return CWinApp::ExitInstance(); }
重写函数
BOOL CXApp::PumpMessage() { // TODO: 在此添加专用代码和/或调用基类 if (m_bCEFInitialized) CefDoMessageLoopWork(); return CPUMPKINPWinApp::PumpMessage(); }
对话框初始化函数
BOOL CXDlg::OnInitDialog() { CefWindowInfo window_info; CRect rt; GetWindowRect(&rt); window_info.SetAsChild(this->GetSafeHwnd(), rt); CefRefPtr<ClientHandler> handler(new ClientHandler()); m_cefHandler = handler; CefBrowserSettings browser_settings; std::string url; url = "http://www.baidu.com/"; CefBrowserHost::CreateBrowser(window_info, handler.get(), url, browser_settings, NULL); } void CXDlg::OnSize(UINT nType, int cx, int cy) { CWnd* cefwindow = FindWindowEx(this->GetSafeHwnd(), NULL, L"CefBrowserWindow", NULL); if (cefwindow) { cefwindow->MoveWindow(0, 0, cx, cy); } }
//加载其他网页时调用
CefBrowser* pBrowser = m_cefHandler->m_pBrowser; CefRefPtr<CefFrame> pMainFram = pBrowser->GetMainFrame(); if (pMainFram) { std::string s = "www.baidu.com"; pMainFram->LoadURL(s.c_str()); }
下载地址
相关文章推荐
- Ubuntu配置LAMP+MediaWiki及常见问题
- 沼泽鳄鱼 矩阵乘法
- Node.js简介
- Date picker 控件简介
- JUnit单元测试--JUnit简介
- csu 1329 一行盒子
- 10267 - Graphical Editor
- 奶牛接力 矩阵乘法
- POJ 3237 Tree (树链剖分 路径剖分 线段树的lazy标记)
- poj2352题解
- 家谱 并差集
- Recycleview 使用中的问题
- 《学习笔记》之JAVA设计模式--原型模式
- 成为程序员的一些基本"法则"
- 百度地图--定位
- BZOJ 1088 枚举 + 推
- 阅读程序(3)
- Struts2国际化
- Tomcat 的运行机制
- WebView实现html文件选择(input type=file),兼容安卓6.0