被催更了,接上篇 。环境已经准备完毕。
创一个空白项目,配置相关环境。
1.启动Vs2015创建一个空白项目。
确定 --》下一步 --》选空项目 --》完成
2.添加一个c++文件
main.cc文件如下:
#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
{
public:
virtual ~MyClient() {}
public:
virtual CefRefPtr<CefLifeSpanHandler> GetLifeSpanHandler() override
{
return this;
}
public:
virtual void OnBeforeClose(CefRefPtr<CefBrowser> browser) override
{
CefQuitMessageLoop();
}
private:
IMPLEMENT_REFCOUNTING(MyClient);
};
class MyApp : public CefApp, public CefBrowserProcessHandler
{
public:
virtual ~MyApp() {}
virtual CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override { return this; }
virtual void OnContextInitialized() override
{
CEF_REQUIRE_UI_THREAD();
CefWindowInfo window_info;
CefRefPtr<MyClient> client(new MyClient());
window_info.SetAsPopup(NULL, "cefsimple");
CefBrowserSettings browser_settings;
CefString url = "http://www.baidu.com";
CefBrowserHost::CreateBrowser(window_info, client, url, browser_settings, NULL);
}
private:
IMPLEMENT_REFCOUNTING(MyApp);
};
int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
CefMainArgs main_args(hInstance);
int exit_code = CefExecuteProcess(main_args, NULL, NULL);
if (exit_code >= 0)
{
return exit_code;
}
CefSettings settings;
settings.no_sandbox = true;
auto myApp = CefRefPtr<MyApp>(new MyApp());
CefInitialize(main_args, settings, myApp.get(), NULL);
CefRunMessageLoop();
CefShutdown();
return 0;
}
3.在生成的工程里右键--》属性
常规设置:目标平台版本可以选择你需要的。
C/C++--》附加包含目录
C/C++--》代码生成--》运行库
链接器--》所有选项-》附加库目录
链接器--》所有选项-》附加依赖项
生成事件--》后期生成事件--》命令行
4.生成项目
输出完整清单
1>------ 已启动全部重新生成: 项目: cefsimple, 配置: Debug Win32 ------
1> main.cc
1> cefsimple.vcxproj -> D:\Projects\cefsimple\Debug\cefsimple.exe
1> cefsimple.vcxproj -> D:\Projects\cefsimple\Debug\cefsimple.pdb (Full PDB)
1> D:\ceflibs\Debug\chrome_elf.dll -> D:\Projects\cefsimple\Debug\chrome_elf.dll
1> D:\ceflibs\Debug\d3dcompiler_43.dll -> D:\Projects\cefsimple\Debug\d3dcompiler_43.dll
1> D:\ceflibs\Debug\d3dcompiler_47.dll -> D:\Projects\cefsimple\Debug\d3dcompiler_47.dll
1> D:\ceflibs\Debug\libcef.dll -> D:\Projects\cefsimple\Debug\libcef.dll
1> D:\ceflibs\Debug\libEGL.dll -> D:\Projects\cefsimple\Debug\libEGL.dll
1> D:\ceflibs\Debug\libGLESv2.dll -> D:\Projects\cefsimple\Debug\libGLESv2.dll
1> D:\ceflibs\Debug\widevinecdmadapter.dll -> D:\Projects\cefsimple\Debug\widevinecdmadapter.dll
1> 复制了 7 个文件
1> D:\ceflibs\Debug\natives_blob.bin -> D:\Projects\cefsimple\Debug\natives_blob.bin
1> D:\ceflibs\Debug\snapshot_blob.bin -> D:\Projects\cefsimple\Debug\snapshot_blob.bin
1> 复制了 2 个文件
1> D:\ceflibs\Resources\cef.pak -> D:\Projects\cefsimple\Debug\cef.pak
1> D:\ceflibs\Resources\cef_100_percent.pak -> D:\Projects\cefsimple\Debug\cef_100_percent.pak
1> D:\ceflibs\Resources\cef_200_percent.pak -> D:\Projects\cefsimple\Debug\cef_200_percent.pak
1> D:\ceflibs\Resources\cef_extensions.pak -> D:\Projects\cefsimple\Debug\cef_extensions.pak
1> D:\ceflibs\Resources\devtools_resources.pak -> D:\Projects\cefsimple\Debug\devtools_resources.pak
1> D:\ceflibs\Resources\icudtl.dat -> D:\Projects\cefsimple\Debug\icudtl.dat
1> D:\ceflibs\Resources\locales\am.pak -> D:\Projects\cefsimple\Debug\locales\am.pak
1> D:\ceflibs\Resources\locales\ar.pak -> D:\Projects\cefsimple\Debug\locales\ar.pak
1> D:\ceflibs\Resources\locales\bg.pak -> D:\Projects\cefsimple\Debug\locales\bg.pak
1> D:\ceflibs\Resources\locales\bn.pak -> D:\Projects\cefsimple\Debug\locales\bn.pak
1> D:\ceflibs\Resources\locales\ca.pak -> D:\Projects\cefsimple\Debug\locales\ca.pak
1> D:\ceflibs\Resources\locales\cs.pak -> D:\Projects\cefsimple\Debug\locales\cs.pak
1> D:\ceflibs\Resources\locales\da.pak -> D:\Projects\cefsimple\Debug\locales\da.pak
1> D:\ceflibs\Resources\locales\de.pak -> D:\Projects\cefsimple\Debug\locales\de.pak
1> D:\ceflibs\Resources\locales\el.pak -> D:\Projects\cefsimple\Debug\locales\el.pak
1> D:\ceflibs\Resources\locales\en-GB.pak -> D:\Projects\cefsimple\Debug\locales\en-GB.pak
1> D:\ceflibs\Resources\locales\en-US.pak -> D:\Projects\cefsimple\Debug\locales\en-US.pak
1> D:\ceflibs\Resources\locales\es-419.pak -> D:\Projects\cefsimple\Debug\locales\es-419.pak
1> D:\ceflibs\Resources\locales\es.pak -> D:\Projects\cefsimple\Debug\locales\es.pak
1> D:\ceflibs\Resources\locales\et.pak -> D:\Projects\cefsimple\Debug\locales\et.pak
1> D:\ceflibs\Resources\locales\fa.pak -> D:\Projects\cefsimple\Debug\locales\fa.pak
1> D:\ceflibs\Resources\locales\fi.pak -> D:\Projects\cefsimple\Debug\locales\fi.pak
1> D:\ceflibs\Resources\locales\fil.pak -> D:\Projects\cefsimple\Debug\locales\fil.pak
1> D:\ceflibs\Resources\locales\fr.pak -> D:\Projects\cefsimple\Debug\locales\fr.pak
1> D:\ceflibs\Resources\locales\gu.pak -> D:\Projects\cefsimple\Debug\locales\gu.pak
1> D:\ceflibs\Resources\locales\he.pak -> D:\Projects\cefsimple\Debug\locales\he.pak
1> D:\ceflibs\Resources\locales\hi.pak -> D:\Projects\cefsimple\Debug\locales\hi.pak
1> D:\ceflibs\Resources\locales\hr.pak -> D:\Projects\cefsimple\Debug\locales\hr.pak
1> D:\ceflibs\Resources\locales\hu.pak -> D:\Projects\cefsimple\Debug\locales\hu.pak
1> D:\ceflibs\Resources\locales\id.pak -> D:\Projects\cefsimple\Debug\locales\id.pak
1> D:\ceflibs\Resources\locales\it.pak -> D:\Projects\cefsimple\Debug\locales\it.pak
1> D:\ceflibs\Resources\locales\ja.pak -> D:\Projects\cefsimple\Debug\locales\ja.pak
1> D:\ceflibs\Resources\locales\kn.pak -> D:\Projects\cefsimple\Debug\locales\kn.pak
1> D:\ceflibs\Resources\locales\ko.pak -> D:\Projects\cefsimple\Debug\locales\ko.pak
1> D:\ceflibs\Resources\locales\lt.pak -> D:\Projects\cefsimple\Debug\locales\lt.pak
1> D:\ceflibs\Resources\locales\lv.pak -> D:\Projects\cefsimple\Debug\locales\lv.pak
1> D:\ceflibs\Resources\locales\ml.pak -> D:\Projects\cefsimple\Debug\locales\ml.pak
1> D:\ceflibs\Resources\locales\mr.pak -> D:\Projects\cefsimple\Debug\locales\mr.pak
1> D:\ceflibs\Resources\locales\ms.pak -> D:\Projects\cefsimple\Debug\locales\ms.pak
1> D:\ceflibs\Resources\locales\nb.pak -> D:\Projects\cefsimple\Debug\locales\nb.pak
1> D:\ceflibs\Resources\locales\nl.pak -> D:\Projects\cefsimple\Debug\locales\nl.pak
1> D:\ceflibs\Resources\locales\pl.pak -> D:\Projects\cefsimple\Debug\locales\pl.pak
1> D:\ceflibs\Resources\locales\pt-BR.pak -> D:\Projects\cefsimple\Debug\locales\pt-BR.pak
1> D:\ceflibs\Resources\locales\pt-PT.pak -> D:\Projects\cefsimple\Debug\locales\pt-PT.pak
1> D:\ceflibs\Resources\locales\ro.pak -> D:\Projects\cefsimple\Debug\locales\ro.pak
1> D:\ceflibs\Resources\locales\ru.pak -> D:\Projects\cefsimple\Debug\locales\ru.pak
1> D:\ceflibs\Resources\locales\sk.pak -> D:\Projects\cefsimple\Debug\locales\sk.pak
1> D:\ceflibs\Resources\locales\sl.pak -> D:\Projects\cefsimple\Debug\locales\sl.pak
1> D:\ceflibs\Resources\locales\sr.pak -> D:\Projects\cefsimple\Debug\locales\sr.pak
1> D:\ceflibs\Resources\locales\sv.pak -> D:\Projects\cefsimple\Debug\locales\sv.pak
1> D:\ceflibs\Resources\locales\sw.pak -> D:\Projects\cefsimple\Debug\locales\sw.pak
1> D:\ceflibs\Resources\locales\ta.pak -> D:\Projects\cefsimple\Debug\locales\ta.pak
1> D:\ceflibs\Resources\locales\te.pak -> D:\Projects\cefsimple\Debug\locales\te.pak
1> D:\ceflibs\Resources\locales\th.pak -> D:\Projects\cefsimple\Debug\locales\th.pak
1> D:\ceflibs\Resources\locales\tr.pak -> D:\Projects\cefsimple\Debug\locales\tr.pak
1> D:\ceflibs\Resources\locales\uk.pak -> D:\Projects\cefsimple\Debug\locales\uk.pak
1> D:\ceflibs\Resources\locales\vi.pak -> D:\Projects\cefsimple\Debug\locales\vi.pak
1> D:\ceflibs\Resources\locales\zh-CN.pak -> D:\Projects\cefsimple\Debug\locales\zh-CN.pak
1> D:\ceflibs\Resources\locales\zh-TW.pak -> D:\Projects\cefsimple\Debug\locales\zh-TW.pak
1> 复制了 59 个文件
========== 全部重新生成: 成功 1 个,失败 0 个,跳过 0 个 ==========
5.D:\Projects\cefsimple\Debug\cefsimple.exe
OK 到此为止我们已经用了一个干净的CEF项目。
预计下一篇:
CEF小白人系列10-代码实现Command-Line模式。
问题:
Q&A
学习交流:
QQ群:14764183
加入验证标注 cef入坑。