一起学libcef--源码文件介绍(VS2015运行DEMO)

来源:互联网 发布:新加坡 经济形势 数据 编辑:程序博客网 时间:2024/06/05 05:40

昨天的博客《一起学libcef–开篇(下载、CMake的使用)》讲诉如何下载CEF,并如何得到对应vs版本的解决方案。

今天就展示一下,得到的工程文件夹中文件的作用。

include – 这个文件夹里面放CEF客户应用程序所需的头文件
libcef – 此文件夹存放CEF的静态库
libcef_dll – 此文件夹CEF的动态拉链库
tests – 此文件夹存放测试的例子
cefclient – 一个简单的客户程序
cefsimple–一个简单的例子
unittests – CEF界面单元测试

下面看一下:
这里写图片描述

下面就是运行cefsimple的界面了:
这里写图片描述

下面就是windows的入口函数:

#include <windows.h>#include "cefsimple/simple_app.h"#include "include/cef_sandbox_win.h"// When generating projects with CMake the CEF_USE_SANDBOX value will be defined// automatically if using the required compiler version. Pass -DUSE_SANDBOX=OFF// to the CMake command-line to disable use of the sandbox.// Uncomment this line to manually enable sandbox support.// #define CEF_USE_SANDBOX 1#if defined(CEF_USE_SANDBOX)// The cef_sandbox.lib static library is currently built with VS2013. It may not// link successfully with other 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);  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);  // SimpleApp implements application-level callbacks. It will create the first  // browser instance in OnContextInitialized() after CEF has initialized.  CefRefPtr<SimpleApp> app(new SimpleApp);  // 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, app.get(), 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  // 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;}Linux Entry Point// cefsimple_linux.cpp#include "cefsimple/simple_app.h"#include <X11/Xlib.h>#include "include/base/cef_logging.h"namespace {int XErrorHandlerImpl(Display *display, XErrorEvent *event) {  LOG(WARNING)        << "X error received: "        << "type " << event->type << ", "        << "serial " << event->serial << ", "        << "error_code " << static_cast<int>(event->error_code) << ", "        << "request_code " << static_cast<int>(event->request_code) << ", "        << "minor_code " << static_cast<int>(event->minor_code);  return 0;}int XIOErrorHandlerImpl(Display *display) {  return 0;}}  // namespace// Entry point function for all processes.int main(int argc, char* argv[]) {  // Provide CEF with command-line arguments.  CefMainArgs main_args(argc, argv);  // SimpleApp implements application-level callbacks. It will create the first  // browser instance in OnContextInitialized() after CEF has initialized.  CefRefPtr<SimpleApp> app(new SimpleApp);  // 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, app.get(), NULL);  if (exit_code >= 0) {    // The sub-process has completed so return here.    return exit_code;  }  // Specify CEF global settings here.  CefSettings settings;  // Install xlib error handlers so that the application won't be terminated  // on non-fatal errors.  XSetErrorHandler(XErrorHandlerImpl);  XSetIOErrorHandler(XIOErrorHandlerImpl);  // Initialize CEF for the browser process.  CefInitialize(main_args, settings, app.get(), NULL);  // Run the CEF message loop. This will block until CefQuitMessageLoop() is  // called.  CefRunMessageLoop();  // Shut down CEF.  CefShutdown();  return 0;}

既然源码可以运行了,我们就可以学习了。
但是源码过于庞大,我们不想太深入理解的话,就想着如何在自己的程序中使用libcef.dll这个库,这就是接下来要讨论的内容。

1 0