CEF3:用CEF3实现最简单的浏览器
来源:互联网 发布:zookeeper mysql 实战 编辑:程序博客网 时间:2024/06/05 07:40
本例开发环境:WIN10 + VS2015
如果还没有编译CEF3库,请见:Windows下用VS2015编译CEF3
创建一个空的 Windows 应用程序,命名为 SimpleBrowser,如下图:
新建 main.cpp ,编写如下代码:
#include "include/cef_app.h"#include "include/cef_browser.h"#include "include/cef_client.h"#include "include/wrapper/cef_closure_task.h"#include "include/wrapper/cef_helpers.h"#include <Windows.h>class MyClient : public CefClient, public CefLifeSpanHandler{ // Constructor & Destructorpublic: virtual ~MyClient() {} // CefClient methods:public: virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override { return this; } // CefLifeSpanHandler methods:public: virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override { CefQuitMessageLoop(); }private: // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(MyClient);};// Implement application-level callbacks for the browser process.class MyApp : public CefApp, public CefBrowserProcessHandler{public: virtual ~MyApp() {} // CefApp methods: virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override { return this; } // CefBrowserProcessHandler methods: virtual void OnContextInitialized() override { CEF_REQUIRE_UI_THREAD(); // Information used when creating the native window. CefWindowInfo window_info; // SimpleHandler implements browser-level callbacks. CefRefPtr<MyClient> client(new MyClient()); // On Windows we need to specify certain flags that will be passed to // CreateWindowEx(). window_info.SetAsPopup(NULL, "cefsimple"); // Specify CEF browser settings here. CefBrowserSettings browser_settings; // Create the first browser window. CefString url = "http://www.baidu.com"; CefBrowserHost::CreateBrowser(window_info, client, url, browser_settings, NULL); }private: // Include the default reference counting implementation. IMPLEMENT_REFCOUNTING(MyApp);};int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow){ // Provide CEF with command-line arguments. CefMainArgs main_args(hInstance); // CEF applications have multiple sub-processes (render, plugin, GPU, etc) // that share the same executable. This function checks the command-line and, // if this is a sub-process, executes the appropriate logic. int exit_code = CefExecuteProcess(main_args, NULL, NULL); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; } // Specify CEF global settings here. CefSettings settings; settings.no_sandbox = true; // SimpleApp implements application-level callbacks for the browser process. // It will create the first browser instance in OnContextInitialized() after // CEF has initialized. auto myApp = CefRefPtr<MyApp>(new MyApp()); // Initialize CEF. CefInitialize(main_args, settings, myApp.get(), NULL); // Run the CEF message loop. This will block until CefQuitMessageLoop() is // called. CefRunMessageLoop(); // Shut down CEF. CefShutdown(); return 0;}
[工程属性] -> [C/C++] ,将 cef 库的 include 所在目录添加到 [附加包含目录]:
[工程属性] -> [链接器],设置好 [附加库目录] 和 [附加依赖项]:
[工程属性] -> [后期生成事件],在命令行里输入如下内容,将依赖的二进制和资源拷贝过来。另外注意需要将 manifest 清单文件嵌入到最后生成的 exe 中,否则可能无法正常运行。
mt.exe -nologo -manifest "G:\libs\cef\manifest\cef.exe.manifest" "G:\libs\cef\manifest\compatibility.manifest" -outputresource:"$(OutDir)$(TargetFileName)";#1xcopy G:\libs\cef\lib\Debug\*.dll $(OutDir) /Y /E /Fxcopy G:\libs\cef\lib\Debug\*.bin $(OutDir) /Y /E /Fxcopy G:\libs\cef\Resources\* $(OutDir) /Y /E /F
编译,运行,效果如下:
以上就是用 CEF3 开发的最简单的浏览器。
阅读全文
1 0
- CEF3:用CEF3实现最简单的浏览器
- cef3结合duilib实现浏览器功能
- CEF3:Windows下用VS2015编译CEF3
- CEF3控件的安装
- CEF3的使用说明
- 使用cef3开发的浏览器不支持flash问题的解决
- CEF3:CEF3关闭流程
- CEF3:CEF3多进程
- 如何利用CEF3创建一个简单的应用程序 (Windows Platform)
- CEF3的各个类的作用和实现
- CEF3的各个类的作用和实现
- CEF3入门
- 编译CEF3:VS2015+CEF3.3202
- CEF3 笔记二(常用类的介绍)
- CEF3 笔记三(常用类的介绍)
- CEF3写Cookie的示例代码段
- CEF3 源码的下载和编译
- cef3加载flash崩溃问题的解决
- 1.4 基本语句
- math类以及单例模式
- mysql表情符录入异常:Incorrect string value: ...for column...
- K Best [二分]
- c#_初学者基础语法及运算符号
- CEF3:用CEF3实现最简单的浏览器
- openlayer读取三种类型的本地瓦片的计算公式
- Maven打包的三种方式
- 1.5 函数和预处理
- shiro学习——高级概述(二)
- STL空间配置器的union obj
- 内存数据库技术选型
- c#后台移除某个元素方法总结
- HBASE 概述