regarding cef message loop

Do not post support requests, bug reports or feature requests. Discuss CEF here. Non-CEF related discussion goes in General Discussion!

regarding cef message loop

Postby giridharb54 » Mon Dec 09, 2013 8:52 am

Hi all,

I have an MDI application and I am integrating Cef3 with it. I have a window which is child of parent window. When i use cefrunmessageloop() it is registering or acting as the parent message loop. how do I hook up the message look with the child?? Please let me know

Regards,
Giri
giridharb54
Expert
 
Posts: 100
Joined: Thu Oct 17, 2013 2:15 am

Re: regarding cef message loop

Postby magreenblatt » Mon Dec 09, 2013 10:06 am

What framework are you using for the MDI application? You will need to integrate CEF with the framework's message loop by calling CefDoMessageLoopWork in a timely manner. Also, please do not post the same topic multiple times -- if you want to change the description just edit the existing topic.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: regarding cef message loop

Postby giridharb54 » Mon Dec 09, 2013 3:11 pm

Hi,
Sorry for posting it multiple times. What do you mean by timely manner??? I have used cefdomessageloopwork() as below
Code: Select all
// GT_HelloWorldWin32.cpp
// compile with: /D_UNICODE /DUNICODE /DWIN32 /D_WINDOWS /c

#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>

#include "include/cef_app.h"
#include "include/cef_base.h"
#include "include/cef_browser.h"
#include "include/cef_client.h"
#include "include/cef_command_line.h"
#include "include/cef_frame.h"
#include "include/cef_runnable.h"
#include "include/cef_web_plugin.h"
#include "clienthandler.h"
#include "cefapplicationhandler.h"

// Global variables

// The main window class name.


CefRefPtr<clienthandler> g_handler(new clienthandler);
CefRefPtr<CefBrowser> browser;
// Forward declarations of functions included in this code module:


//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//

LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
    switch(msg)
   {
     

   case WM_DESTROY:
      {
         CefQuitMessageLoop();
         PostQuitMessage(0);
         return 0;
      }
      break;

   case WM_CREATE:
   {
      RECT rect;
      GetClientRect(hWnd, &rect);
      CefWindowInfo info;
      info.SetAsChild(hWnd, rect);
      CefBrowserSettings settings;
      std::string path = "file:///C:/Users/GBM/Documents/Visual%20Studio%202010/Projects/cefapplication1/cefapplication1/index.html";
      CefBrowserHost::CreateBrowserSync(info, g_handler.get(),"https://www.google.com" ,settings);
    
      }
      break;

   case WM_COMMAND:
      {
     
      }
      break;
    }
   return DefWindowProc(hWnd,msg,wParam,lParam);
}

int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    // Register the window class.
    const wchar_t CLASS_NAME[]  = L"Sample Window Class";
   
    WNDCLASS wc = { };

    wc.lpfnWndProc   = WndProc;
    wc.hInstance     = hInstance;
    wc.lpszClassName = CLASS_NAME;

    RegisterClass(&wc);
   
   CefRefPtr<cefapplicationhandler> cefApplication(new cefapplicationhandler);
   CefMainArgs main_args(hInstance);
   CefSettings appSettings;
    // Create the window.
   CefInitialize(main_args,appSettings, cefApplication.get());
    HWND hwnd = CreateWindowEx(
        0,                              // Optional window styles.
        CLASS_NAME,                     // Window class
        L"Learn to Program Windows",    // Window text
        WS_OVERLAPPEDWINDOW,            // Window style

        // Size and position
        CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,

        NULL,       // Parent window   
        NULL,       // Menu
        hInstance,  // Instance handle
        NULL        // Additional application data
        );

    if (hwnd == NULL)
    {
        return 0;
    }
   
    ShowWindow(hwnd, nCmdShow);
   MSG msg;
   BOOL bRet;
     while ((bRet = GetMessage(&msg, NULL, 0, 0)) != 0) {
        CefDoMessageLoopWork();
        TranslateMessage(&msg);
        DispatchMessage(&msg);
     }
   
   CefShutdown();
    return 0;
}

It works fine for me. But there is lag or delay in handling Ui events on the browser. Why is this???
giridharb54
Expert
 
Posts: 100
Joined: Thu Oct 17, 2013 2:15 am

Re: regarding cef message loop

Postby magreenblatt » Mon Dec 09, 2013 3:44 pm

In the example you posted you should just use CefRunMessageLoop(). If you're using a framework where you can't run the message loop yourself then you can use CefDoMessageLoopWork or CefSettings.multi_threaded_message_loop. See https://code.google.com/p/chromiumembed ... ail?id=189 for discussion related to CefDoMessageLoopWork.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: regarding cef message loop

Postby giridharb54 » Tue Dec 10, 2013 3:43 am

How to integrate cef message loop with MFC message map???
giridharb54
Expert
 
Posts: 100
Joined: Thu Oct 17, 2013 2:15 am

Re: regarding cef message loop

Postby magreenblatt » Tue Dec 10, 2013 9:16 am

giridharb54 wrote:How to integrate cef message loop with MFC message map???

You can use PreTranslateMessage to call CefDoMessageLoopWork or use multi_threaded_message_loop.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm


Return to CEF Discussion

Who is online

Users browsing this forum: No registered users and 180 guests