How to handle an event message while using chrome embedded framework (CEF)?

6.1k views Asked by At

I'm using Chromium Embedded Framework(CEF) to develop a windows desktop application(using C++/Win32, No MFC). I have used the sample "cefsimple" project and extended on it till now. I have added "Handlers" for keyboard events etc. Everything works fine till now, I can get the handle of the browser window and play with it.

Now I couldn't find a way to handle the event messages received from outside. Example: A third party application sends some data to my application and I need to receive it. Or I need to handle mouse events.

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

This is my current main function. Am I missing something here? CefRunMessageLoop() runs the custom CEF messaging loop and I have no way of receiving those messages.

I have been trying to get a solution for this for past 2 days :(

1

There are 1 answers

4
PhysicalEd On BEST ANSWER

see CefDoMessageLoopWork(), this is meant to be called from your own message loop. So you could implement your windows message loop and call this on idle.

This is from the comment to cef_do_message_loop_work() which is what CefDoMessageLoopWork() calls and gives more information:

// 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.

So you will have to implement your own Windows event loop, but you would have to to handle your own mouse events etc. anyway.