【问题标题】:How to handle an event message while using chrome embedded framework (CEF)?使用 chrome 嵌入式框架 (CEF) 时如何处理事件消息?
【发布时间】:2015-06-09 23:54:01
【问题描述】:

我正在使用 Chromium Embedded Framework(CEF) 开发 Windows 桌面应用程序(使用 C++/Win32,无 MFC)。我已经使用了示例“cefsimple”项目并将其扩展到现在。我已经为键盘事件等添加了“处理程序”。到目前为止一切正常,我可以获取浏览器窗口的句柄并使用它。

现在我找不到处理从外部收到的事件消息的方法。示例:第三方应用程序向我的应用程序发送了一些数据,我需要接收它。或者我需要处理鼠标事件。

  CefRefPtr<SimpleApp> app(new SimpleApp);
  int exit_code = CefExecuteProcess(main_args, app.get(), sandbox_info);
  if (exit_code >= 0) {
    return exit_code;
  }

  // Specify CEF global settings here.
  CefSettings settings;

#if !defined(CEF_USE_SANDBOX)
  settings.no_sandbox = true;
#endif

  settings.single_process = true;
  settings.windowless_rendering_enabled = true;


  // 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();

这是我目前的主要功能。我在这里错过了什么吗? CefRunMessageLoop() 运行自定义 CEF 消息循环,我无法接收这些消息。

过去两天我一直在尝试解决这个问题:(

【问题讨论】:

  • 我试过 OnProcessMessageReceived() 但它适用于铬线程之间的 IPC。

标签: c++ winapi visual-c++ chromium-embedded


【解决方案1】:

请参阅 CefDoMessageLoopWork(),这意味着从您自己的消息循环中调用。所以你可以实现你的 windows 消息循环并在空闲时调用它。

这是对 cef_do_message_loop_work() 的评论,这是 CefDoMessageLoopWork() 调用并提供更多信息:

// Perform a single iteration of CEF message loop processing. This function is
// used to integrate the CEF message loop into an existing application message
// loop. Care must be taken to balance performance against excessive CPU usage.
// This function should only be called on the main application thread and only
// if cef_initialize() is called with a CefSettings.multi_threaded_message_loop
// value of false (0). This function will not block.

因此,您必须实现自己的 Windows 事件循环,但无论如何您都必须处理自己的鼠标事件等。

【讨论】:

  • 我正在尝试一种简单的方法来做到这一点。如果我必须调用“CefDoMessageLoopWork()”,我可以在典型的 Windows 消息处理循环中添加它吗?
  • 似乎只需在典型的 while 消息循环中调用此函数即可。谢谢。
猜你喜欢
  • 2014-02-05
  • 2019-02-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-25
  • 2016-02-26
  • 1970-01-01
相关资源
最近更新 更多