libcef是一个非常优秀的嵌入式浏览开源库,可以在C++,Java,C#等常用语言中使用,在本文中,主要介绍在Vs2017环境下的编译使用。
1.下载第一步,需要下载libcef的版本,现今libcef的下载地址为:https://cef-builds.spotifycdn.com/index.html#windows64,本文默认已经安装好Vs2017和CMake。本文选择的版本为:cef_binary_79.0.10+ge866a07+chromium-79.0.3945.88,为至今日较新版本。
2.构建项目 项目的构建文件CMakeLists.txt,位于根目录下,根据下图选择:
然后选择Vs2017 Win64对应的编译器。
采用Vs2017打开解决方案cef.sln,如下图所示:
打开后项目解决方案如下:
编译时,可以先编译libcef_dll_wrapper项目,再编译其他项目。
范例代码如下:
#include#include "include/cef_sandbox_win.h" #include "tests/cefsimple/simple_app.h" #if defined(CEF_USE_SANDBOX) // The cef_sandbox.lib static library may not link successfully with all VS // versions. #pragma comment(lib, "cef_sandbox.lib") #endif // Entry point function for all processes. int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // Enable High-DPI support on Windows 7 or newer. CefEnableHighDPISupport(); void* sandbox_info = NULL; #if defined(CEF_USE_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 // 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, sandbox_info); if (exit_code >= 0) { // The sub-process has completed so return here. return exit_code; } // Specify CEF global settings here. CefSettings settings; #if !defined(CEF_USE_SANDBOX) settings.no_sandbox = true; #endif // SimpleApp implements application-level callbacks for the browser process. // It will create the first browser instance in onContextInitialized() after // CEF has initialized. CefRefPtr app(new SimpleApp); // Initialize CEF. CefInitialize(main_args, settings, app.get(), sandbox_info); // Run the CEF message loop. This will block until CefQuitMessageLoop() is // called. CefRunMessageLoop(); // Shut down CEF. CefShutdown(); return 0; }
合理的脚本代码可以有效的提高工作效率,减少重复劳动。
欢迎光临知了软件开发网络平台,本公司定制开发各类软件,主要方向为桌面专业软件开发、插件定制开发、微信小程序(各类小程序)、网站定制开发和App开发,桌面软件主要包括文字图形识别类软件,信息管理类软件,3D打印类软件,视频类软件以及其它涉及专业的各类图形图像处理软件。插件包含AE插件,AI插件,PS插件,PDF插件,3DMAX插件以及Word,Excel等Office插件开发。详情请咨询,微信QQ:312117271,手机:18928899728,邮箱: anjingzhi_sea@163.com.
公司网址:http://www.zhiliaos.com



