1.å¦ä½å©ç¨CEF3å建ä¸ä¸ªç®åçåºç¨ç¨åº
2.使用CEF(四)— 在QT中集成CEF(1)基本集成
3.cef是什么文件夹
å¦ä½å©ç¨CEF3å建ä¸ä¸ªç®åçåºç¨ç¨åº
å¼å§
é¦å ï¼æ ¹æ®èªèº«æ使ç¨çå¼åå¹³å°ï¼å¯ä»¥å» è¿é ä¸è½½å¯¹åºçåå¸çæ¬ãé对è¿ä¸ªæç¨ï¼æ们éè¦ä¸è½½æè æ´æ°ççæ¬ãå½åæ¯æçå¹³å°æWindows, LinuxåMac OS Xãæ¯ä¸ä¸ªçæ¬é½å å«äºå½å¨ç¹å®å¹³å°ä¸ç¼è¯ç¹å®çæ¬CEF3æ¶æéè¦çæææ件åèµæºãæ¨å¯ä»¥éè¿å å«å¨éè¾¹ç REDME.txt æ件æè å¨Wikiä¸GeneralUsage ä¸ç Getting Startedï¼äºè§£æ¯ä¸ªåå¸çæ¬çå ·ä½å 容åç»èã
ç¼è¯åå¸çæ¬ä¸ç项ç®
以CEFåå¸çæ¬ä¸ºåºç¡å¼åçåºç¨ç¨åºå¯ä»¥ä½¿ç¨æ åçå¹³å°ç¼è¯å·¥å ·è¿è¡ç¼è¯æ§è¡ãå æ¬ Windows å¹³å°ä¸ç Visual Studio, Mac OS X å¹³å°ä¸ç Xcode, 以å Linux å¹³å°ä¸ç gcc/makeãé对平å°çä¸åï¼é¡¹ç®çç¼è¯è¿ç¨ä¹æäºè®¸çä¸ååè¦æ±ã
Windows
Windows å¹³å°ä¸ç¼è¯ Cefsimple æ¥éª¤ï¼
1. ç¨å¯¹åºç Visual Studio çæ¬æå¼é¡¹ç®è§£å³æ¹æ¡ã举个ä¾åï¼å¦æä½ å®è£ çæ¯ Visual Studio ï¼ é£ä¹ï¼æå¼çå°±æ¯ cesimple.slnã
2. å¦æä½ ä¸è½½çæ¯ xçæ¬ï¼è¯·ç¡®ä¿ä½ éæ©çæ¯ xçå¼åå¹³å°ã
3. å¼å§ç¼è¯ã
4. å¦æç¼è¯éè¿ï¼é£ä¹ï¼å¨å½å解å³æ¹æ¡çç®å½ä¸ï¼å°åºç°âout/Debugâï¼æè âout/Releaseâï¼æ件夹ã
5. æ§è¡æä»¶å¤¹ä¸ cefsimple.exe, ç¡®ä¿è½æ£ç¡®è¿è¡ã
å è½½ä¸ä¸ªèªå®ä¹URL
cefsimple项ç®ä¸é»è®¤å è½½çURLæ¯ google.comï¼å½ç¶ï¼ä½ ä¹å¯ä»¥ç¨èªå®ä¹ç URL å»æ¿ä»£å®ï¼ææ¹ä¾¿çå°±æ¯éè¿å½ä»¤è¡æå®ã
# Load the local file âc:\example\example.htmlâ
cefsimple.exe --url=file://c:/example/example.html
é¤äºå½ä»¤è¡çæ¹æ³ï¼ä¹å¯ä»¥éè¿ç´æ¥ä¿®æ¹å¨ cefsimple/simple.cpp æ件ä¸ç代ç ï¼è¾¾å°ä½ çç®çã
# Load the local file âc:\example\example.htmlâ
â¦
if (url.empty())
url = file://c:/example/example.html;
åºç¨ç¨åºç»æ
ææç CEF åºç¨ç¨åºé½æä¸ä¸ä¸»è¦ç»æé¨åï¼
1. CEF çå¨æé¾æ¥åº ã(å¨ Windows å¹³å°ä¸å°±æ¯ libcef.dll)
2. æ¯æåºãï¼ICU, FFMPEGçï¼
3. èµæºã(html/js/css, stringsç)
4. 客æ·ç«¯æ§è¡æ件ã(æ¬æç¨ä¸å°±æ¯ cefsimple.exe.)
è¦ç¹ï¼å¿ çï¼
1. CEF 使ç¨çæ¯å¤è¿ç¨ãåºç¨ç¨åºä¸»è¿ç¨æ¯æµè§å¨è¿ç¨ï¼èå ¶ä»åè¿ç¨æ¯ç± renderer, plugins, GPUçå建ã
2. å¨ Windows å Linux å¹³å°ä¸çæ§è¡æ件å¯ä»¥è¢«ä¸»è¿ç¨ååè¿ç¨ä½¿ç¨ã
3. CEF ä¸ææè¿ç¨é½å¯ä»¥æ¯å¤çº¿ç¨çãCEFæä¾äºè®¸å¤åè½åæ¥å£å¨ä¸åç线ç¨ä¸ä¼ éä»»å¡ã
4. ä¸äºåè°æ¹æ³åå½æ°åªè½å¨ç¹å®çè¿ç¨æè 线ç¨ä¸ä½¿ç¨ãå¨ä½ 第ä¸æ¬¡ä½¿ç¨æ°çåè°æ¹æ³æè å½æ°ä¹åï¼è¯·ç¡®ä¿ä½ å·²ç»é è¯»äº API 头æ件ä¸æºç ï¼ç使ç¨è¦æ±ã
æµç¨åæ
cefsimple åºç¨ç¨åºé¦å åå§åCEFï¼ç¶åå建äºä¸ä¸ªç®åçå¼¹åºæµè§å¨çªå£ãå½å ³éäºææçæµè§å¨çªå£ï¼åºç¨ç¨åºå°±ä¼ç»æãç¨åºæ§è¡æµç¨å¦ä¸ï¼
1. ç³»ç»æ§è¡å ¥å£ç¹å½æ°(main or wWinMain)ï¼å¹¶å建æµè§å¨è¿ç¨ã
2. å ¥å£ç¹å½æ°ï¼
1. å建è½å¤å¤çè¿ç¨çº§å«çåè°æ¹æ³ç SimpleApp å®ä¾ã
2. åå§å CEFï¼è¿å ¥ CEF æ¶æ¯å¾ªç¯ã
3. åå§å CEF ä¹åï¼è°ç¨ SimpleApp::OnContextInitialized() ãè¿ä¸ªæ¹æ³ä¸ï¼
1. å建åä¾ç SimpleHandler ã
2. ç± CefBrowserHost::CreateBrowsersync() æ¹æ³å建ä¸ä¸ªæµè§å¨çªå£ã
4. ææçæµè§å¨å ±äº« SimpleHandler å®ä¾ï¼ æ¤å®ä¾è½å®å¶æµè§å¨è¡ä¸ºãå¤çæµè§å¨ç¸å ³åè°æ¹æ³(life span, loading state, title displayç)ã
5. å½ä¸ä¸ªæµè§å¨çªå£å ³éçæ¶åï¼è°ç¨ SimpleHandler::OnBeforeClose() ãå½ææçæµè§å¨çªå£å ¨é¨å ³éæ¶ï¼OnBeforeClose() å½æ°å°±ä¼æ§è¡è·³åº CEF æ¶æ¯å¾ªç¯çè¡ä¸ºï¼éåºåºç¨ç¨åºã
å ¥å£ç¹å½æ°
ç¨åºçè¿è¡å¼å§äºæµè§å¨è¿ç¨ä¸çå ¥å£ç¹å½æ°ãè¿ä¸ªå½æ°ä¼åå§å CEF 以åææè·æä½ç³»ç»æå ³ç对象ã
Windows
#include <windows.h>
#include "cefsimple/simple_app.h"
#include "include/cef_sandbox_win.h"
// Set to 0 to disable sandbox support.
#define CEF_ENABLE_SANDBOX 1
#if CEF_ENABLE_SANDBOX
// The cef_sandbox.lib static library is currently built with VS. 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 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
// 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 !CEF_ENABLE_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;
}
SimpleApp
SimpleApp è´è´£å¤çè¿ç¨çº§å«çåè°æ¹æ³ãå®ä¼æé²åºä¸äºå¨å¤è¿ç¨ä¸å ±äº«æè 被ç¹å®è¿ç¨ä½¿ç¨çæ¥å£åæ¹æ³ãCefBrowserProcessHandler æ¥å£ï¼å¨æµè§å¨è¿ç¨ä¸è°ç¨ãè¿æä¸ä¸ªè¢«åç¦»åº CefBrowserProcessHandler æ¥å£ï¼ä¾å项ç®æ²¡æå±ç¤ºï¼åªä¼å¨æ¸²æè¿ç¨ä¸è¢«è°ç¨ãç±äº CefBrowserProcessHandler ä¸å å®ç°äº CefApp, åæ¶è¿æ CefBrowserProcessHandlerï¼æ以å®çè¿åå¼å¿ é¡»æ¯[this]ã
// simple_app.h
#include "include/cef_app.h"
class SimpleApp : public CefApp,
public CefBrowserProcessHandler {
public:
SimpleApp();
// CefApp methods:
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler()
OVERRIDE { return this; }
// CefBrowserProcessHandler methods:
virtual void OnContextInitialized() OVERRIDE;
private:
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(SimpleApp);
};
// simple_app.cpp
#include "cefsimple/simple_app.h"
#include <string>
#include "cefsimple/simple_handler.h"
#include "cefsimple/util.h"
#include "include/cef_browser.h"
#include "include/cef_command_line.h"
SimpleApp::SimpleApp() {
}
void SimpleApp::OnContextInitialized() {
REQUIRE_UI_THREAD();
// Information used when creating the native window.
CefWindowInfo window_info;
#if defined(OS_WIN)
// On Windows we need to specify certain flags that will be passed to
// CreateWindowEx().
window_info.SetAsPopup(NULL, "cefsimple");
#endif
// SimpleHandler implements browser-level callbacks.
CefRefPtr<SimpleHandler> handler(new SimpleHandler());
// Specify CEF browser settings here.
CefBrowserSettings browser_settings;
std::string url;
// Check if a "--url=" value was provided via the command-line. If so, use
// that instead of the default URL.
CefRefPtr<CefCommandLine> command_line =
CefCommandLine::GetGlobalCommandLine();
url = command_line->GetSwitchValue("url");
if (url.empty())
url = "";
// Create the first browser window.
CefBrowserHost::CreateBrowserSync(window_info, handler.get(), url,
browser_settings, NULL);
}
SimpleHandler
SimpleHandler è´è´£å¤çæµè§å¨çº§å«çåè°æ¹æ³ãè¿äºåè°æ¹æ³ä¼å¨æµè§å¨è¿ç¨ä¸æ§è¡ãå¨è¿ä¸ªé¡¹ç®ä¸ï¼é对ææçæµè§å¨ä½¿ç¨ç¸åç CefClient å®ä¾ï¼ä½æ¯å¦æä½ æ¿æï¼å¯ä»¥å¨èªå·±çåºç¨ç¨åºä¸ä½¿ç¨ä¸åç CefClientå®ä¾çã
// simple_handler.h
#include "include/cef_client.h"
#include <list>
class SimpleHandler : public CefClient,
public CefDisplayHandler,
public CefLifeSpanHandler,
public CefLoadHandler {
public:
SimpleHandler();
~SimpleHandler();
// Provide access to the single global instance of this object.
static SimpleHandler* GetInstance();
// CefClient methods:
virtual CefRefPtr<CefDisplayHandler> GetDisplayHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() OVERRIDE {
return this;
}
virtual CefRefPtr<CefLoadHandler> GetLoadHandler() OVERRIDE {
return this;
}
// CefDisplayHandler methods:
virtual void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE;
// CefLifeSpanHandler methods:
virtual void OnAfterCreated(CefRefPtr<CefBrowser> browser) OVERRIDE;
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) OVERRIDE;
// CefLoadHandler methods:
virtual void OnLoadError(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
ErrorCode errorCode,
const CefString& errorText,
const CefString& failedUrl) OVERRIDE;
// Request that all existing browser windows close.
void CloseAllBrowsers(bool force_close);
private:
// List of existing browser windows. Only accessed on the CEF UI thread.
typedef std::list<CefRefPtr<CefBrowser> > BrowserList;
BrowserList browser_list_;
// Include the default reference counting implementation.
IMPLEMENT_REFCOUNTING(SimpleHandler);
};
// simple_handler.cpp
#include "cefsimple/simple_handler.h"
#include <sstream>
#include <string>
#include "cefsimple/util.h"
#include "include/cef_app.h"
#include "include/cef_runnable.h"
namespace {
SimpleHandler* g_instance = NULL;
使用CEF(四)— 在QT中集成CEF(1)基本集成
在QT,一个强大的跨平台C++开发框架,上构建基于CEF(Chrome Embedded Framework)的应用程序,我们之前的文章已经展示了基础的样例,但这些示例主要依赖原生或功能有限的CEF视图。本文将重新开始,蓝月手游源码通过VS,实现一个结合QT和原生窗体的集成项目。环境搭建
本文不依赖QtCreator,而是使用VS和Qt VS Tools来构建环境,前提是你已安装并熟悉QT。安装Qt VS Tools插件
在VS扩展中搜索并安装相应的QT插件,安装后别忘了重启VS。silverlight网站源码配置Qt环境
在Extensions - Qt VS Tools - Options中,配置Qt-VS编译设置。创建Qt项目
在配置完成后,通过VS创建项目,Qt模板将自动出现。我们创建名为QtCefDemo的svn导出源码项目,Qt创建向导随即启动。项目结构
创建完成后,项目的文件结构如下,展示了一个基本的VS IDE下的QT项目。集成CEF环境
为了集成CEF,我们首先需要编译并准备相应的eam免费 源码头文件、库文件和资源文件,包括libcef_dll_wrapper.lib(MDd和MD版本)。项目目录结构
按照步骤,你会看到项目的文件夹结构,包括CefFiles文件夹及其内部的头文件、库文件和资源。母婴会所源码配置manifest文件和VS设置
为CEF项目配置manifest文件,以及头文件和库文件的路径,这里会根据Debug和Release环境自动调整。集成完成后的问题与解决方案
在集成过程中,可能会遇到运行时的库文件问题。需要手动或通过脚本将相关文件复制到输出目录。初始运行可能存在问题,但后续文章将深入探讨解决方法。源码和资源
项目源码可以在我的GitHub仓库找到,链接在此省略。此外,需要下载CefFiles文件夹,可以从网盘获取,链接同样省略。cef是什么文件夹
CEF是Chromium Embedded Framework的缩写,是基于Google Chrominum项目开发的一个web浏览器控件。
CEF是开源的,可以下载源码,去掉自己不需要的模块,然后自己编译,也可以直接使用CEF提供的库,CEF提供的库是libcef.dll,很多程序都有libcef.dll这个动态库,比如qq和evernote,但是大小都不一样,估计是自己裁剪过然后编译的。