【问题标题】:Simple CEF project not show page简单的 CEF 项目不显示页面
【发布时间】:2020-04-09 13:26:29
【问题描述】:

尝试使用 C++ 中的 CEF。制作简单的项目:

#include <Windows.h>

#include <include/cef_app.h>
#include <include/cef_client.h>
#include <include/wrapper/cef_helpers.h>

class Handler : public CefClient {
public:

private:
    IMPLEMENT_REFCOUNTING(Handler);
};

class App : public CefApp, public CefBrowserProcessHandler {
public:
    CefRefPtr<CefBrowserProcessHandler> GetBrowserProcessHandler() override {
        return this;
    }

    void OnContextInitialized() override {
        CEF_REQUIRE_UI_THREAD();

        CefRefPtr<Handler> handler(new Handler);

        CefWindowInfo wndInfo;
        wndInfo.SetAsPopup(0, "Hello world");

        CefBrowserSettings settings;

        std::string url{ "https://stackoverflow.com" };
        CefBrowserHost::CreateBrowser(wndInfo, handler, url, settings, nullptr, nullptr);
    }

private:
    IMPLEMENT_REFCOUNTING(App);
};

int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
    CefEnableHighDPISupport();

    CefMainArgs args(hInstance);
    int ec = CefExecuteProcess(args, nullptr, nullptr);
    if (ec >= 0) {
        return ec;
    }

    CefSettings settings;

    CefRefPtr<App> app(new App);

    CefInitialize(args, settings, app, nullptr);

    CefRunMessageLoop();

    CefShutdown();

    return 0;
}

项目文件夹包含来自cefclient的所有文件(官方cef示例)

08.04.2020  12:21         2 133 001 cef.pak
08.04.2020  12:21           654 037 cef_100_percent.pak
08.04.2020  12:21           808 292 cef_200_percent.pak
08.04.2020  12:21         1 772 827 cef_extensions.pak
08.04.2020  12:21         1 110 016 chrome_elf.dll
08.04.2020  12:21         4 346 120 d3dcompiler_47.dll
08.04.2020  12:21         7 015 266 devtools_resources.pak
08.04.2020  12:21        10 505 952 icudtl.dat
08.04.2020  12:21       158 316 032 libcef.dll
08.04.2020  12:21           391 168 libEGL.dll
08.04.2020  12:21        10 552 832 libGLESv2.dll
08.04.2020  12:44    <DIR>          locales
09.04.2020  18:14           613 247 main.obj
09.04.2020  18:14         3 948 032 Project1.exe
08.04.2020  12:21           606 640 snapshot_blob.bin
08.04.2020  12:49    <DIR>          swiftshader
08.04.2020  12:21           923 968 v8_context_snapshot.bin
09.04.2020  18:14           519 168 vc142.idb
09.04.2020  18:14           847 872 vc142.pdb

为什么我会得到一个空白页?

【问题讨论】:

  • 请不要发布指向外部网站的链接。只需在您的问题中发布文字即可。我编辑了您的问题并从 pastebin 复制了文本,如果需要,请修改我的编辑。
  • 你试过用qt吗
  • 谢谢!我不需要依赖 Qt
  • 我想知道您是否有过使用它的经验,以帮助我决定我应该使用哪一种(铬/qt)

标签: c++ chromium-embedded


【解决方案1】:

解决了。添加清单文件

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">

  <dependency>
    <dependentAssembly>
      <assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
    </dependentAssembly>
  </dependency>

  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!--The ID below indicates application support for Windows Vista -->
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
      <!--The ID below indicates application support for Windows 7 -->
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
      <!--The ID below indicates application support for Windows 8 -->
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
      <!--The ID below indicates application support for Windows 8.1 -->
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
      <!--The ID below indicates application support for Windows 10 -->
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
    </application>
  </compatibility>

  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" />
      </requestedPrivileges>
    </security>
  </trustInfo>

</assembly>

【讨论】:

  • 请告诉我,这个清单文件是什么?为什么添加后一切正常?哪里有写他的?
猜你喜欢
  • 1970-01-01
  • 2013-03-18
  • 2018-07-14
  • 2019-06-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-12-13
相关资源
最近更新 更多