一起学libcef--一个应用libcef的简单例子(windows程序)

本文介绍了如何在Windows环境下利用libcef库创建一个简单的应用程序。首先,通过回顾前文如何搭建libcef运行环境,接着详细阐述了步骤:从打开cefclient源码解决方案,确保其能正常运行,到删除不必要的文件和调整项目为动态链接。然后,逐步创建自己的头文件`ExampleCefApp.h`,定义一个继承自`CefApp`的类;创建`ExampleCefHandler.h`和`ExampleCefHandler.cc`文件,实现事件处理类;最后编写主函数完成应用的基本架构。
摘要由CSDN通过智能技术生成

之前博客《一起学libcef–搭建自己的libcef运行环境(Win32程序,错误C2220解决方案)》讲述了如何在win32程序中搭建libcef的环境,今天就通过一个简单的例子,在windows程序中使用libcef。

现在再重新写一下如何搞?直接在源代码上搞起!
1 打开源码cefclient解决方案
2 确保cefclient例子可以完美运行
3 在cefclient中,除了util.h之外,全部移除
4 manifests 和 resources文件也可以移除(you must remember to remove the additional manifest files from the Visual Studio project file.)
5 libcef_dll_wrapper 是静态链接,所以我们需要更改项目为动态链接。

接下来就要干我们的事儿了:
1 创建一个自己的头文件ExampleCefApp.h, 在这里新建一个类,继承自CefApp:
CefApp 负责所有的工作, 但是这是一个抽象类,需要计数实现
这样, 我们继承自CefApp创建了一个傀儡类,实际上也什么都没做

#include "include/cef_app.h"
class ExampleCefApp : public CefApp
{
   public:
      ExampleCefApp ()
      {
      }
      virtual ~ExampleCefApp ()
      {
      }

   private:
      IMPLEMENT_REFCOUNTING (ExampleCefApp);
};

2创建一个ExampleCefHandler.h文件,这里面实现一个类继承自所有的event handling classes。

#pragma once

#include "include/cef_client.h"
#include "cefclient/util.h"

class ExampleCefHandler : public CefClient,
                          public CefContextMenuHandler,
                          public CefDisplayHandler,
                          public CefDownloadHandler,
                          public CefDragHandler,
                          public CefGeolocationHandler,
                          public CefKeyboardHandler,
                          public CefLifeSpanHandler,
                          public CefLoadHandler,
                          public CefRequestHandler
{
 public:
      ExampleCefHandler();
      virtual ~ExampleCefHandler();
      CefRefPtr<CefBrowser> GetBrowser();

#pragma region CefClient
      // since we are letting the base implementations handle all of the heavy lifting,
      // these functions just return the this pointer
      virtual CefRefPtr<CefContextMenuHandler> GetContextMenuHandler () OVERRIDE;
      virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler () OVERRIDE;
      virtual CefRefPtr<CefDownloadHandler> GetDownloadHandler () OVERRIDE;
      virtual CefRefPtr<CefDragHandler> GetDragHandler () OVERRIDE;
      virtual CefRefPtr<CefGeolocationHandler> GetGeolocationHandler () OVERRIDE;
      virtual CefRefPtr<CefKeyboardHandler> GetKeyboardHandler () OVERRIDE;
      virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler () OVERRIDE;
      virtual CefRefPtr<CefLoadHandler> GetLoadHandler () OVERRIDE;
      virtual CefRefPtr<CefRequestHandler> GetRequestHandler () OVERRIDE;
#pragma endregion // CefClient

#pra
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一苇渡江694

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值