CEF closing/resizing issues inside a big application plugin

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CEF closing/resizing issues inside a big application plugin

Postby flakemarked » Thu Jul 21, 2016 12:51 pm

I'm writing a plugin for a big x64 application in C++. I want the plugin to open a dialog and show a web view of my site.
I'm been able to use WKWebView in macOS and it works well. On Windows I'm evaluating CEF (please let me know of any alternative, ideally I would like it to be Webkit-based).
Let's say the application framework that is hosting my plugin has already created a window for my plugin and has it's own message loop, so I can only receive events in a sort of WindowProc. I can also get the HWND of the window.

My implementation is inspired by cefsimple example, because cefclient is way too complicated. I've implemented the subprocess architecture with the external executable and everything works fine until it's rendering the client area of the window. Then I have problems with closing the window (it crashes) and resizing the window interactively (the window frame is resized but the web view in the client area does not resize).
I've tried all possible combinations, but I've run out of ideas. Namely:
  • If I use CefRunMessageLoop() the web view is rendered correctly but the main application does not process the UI events like close window button. Resize does not work.
  • If I call CefDoMessageLoopWork() myself once in a while (from WindowProc) the web view is rendered correctly and it processes the close button, but it crashes. Resize does not work.
  • If I use settings.multi_threaded_message_loop = true the web view is rendered correctly and I can close the window without crash. The destructor of the window calls CefShutdown(). But if I try to reopen the window it crashes! Are CefInitialize and CefShutdown allowed to be called only once?
    And resizing still does not work. I don't understand why in the cefsimple example resizing works and in my window it does not work.
Besides message processing issues, probably I'm not closing the browser correctly, any advice? Why is so complicated? WKWebView is so straighforward!

Thanks
Marco
flakemarked
Newbie
 
Posts: 3
Joined: Thu Jul 21, 2016 12:45 pm

Re: CEF closing/resizing issues inside a big application plu

Postby magreenblatt » Thu Jul 21, 2016 1:01 pm

Are CefInitialize and CefShutdown allowed to be called only once?

Correct, they can only be called once.

Resize does not work.

Windows will not resize for you automatically, unlike Mac. You need to listen for some resize notification from your application framework and use SetWindowPos to resize the CEF window.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF closing/resizing issues inside a big application plu

Postby flakemarked » Fri Jul 22, 2016 6:32 am

Thank you, I've done some modifications to do initialize and shutdown only once and I don't get any crash now.

Regarding sizing, it works now with the following code. The trick was to use SetWindowPos on the browserHWND rather than the parentHWND. I didn't realize the browser has has a different handle!
Code: Select all
CefWindowHandle browserHWND = browser->GetHost()->GetWindowHandle();
HWND parentHWND = GetParent(browserHWND);
RECT rect = { 0 };
GetClientRect(parentHWND, &rect);
SetWindowPos(browserHWND, NULL, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, SWP_NOZORDER);

The only annoying thing is that when I resize the client area becomes grey and after a while (fraction of second) it is painted correctly. I've tried to use also DeferWindowPos but it does not help.
What's wrong?
flakemarked
Newbie
 
Posts: 3
Joined: Thu Jul 21, 2016 12:45 pm

Re: CEF closing/resizing issues inside a big application plu

Postby magreenblatt » Fri Jul 22, 2016 10:17 pm

Does the gray come from the parent window background? If so, you usual options would be (a) don't draw the parent window background, or (b) change the parent window background color to match your window color so it's less noticeable.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: CEF closing/resizing issues inside a big application plu

Postby flakemarked » Sun Jul 24, 2016 12:05 pm

You were right, it came from the parent window background. It works well by detecting the background paint event and disable it.
Many thanks! :)
flakemarked
Newbie
 
Posts: 3
Joined: Thu Jul 21, 2016 12:45 pm


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 77 guests