I've followed the cefclient example and read the wiki, so I feel like I'm doing things correctly, but perhaps not? Let me state here what's happening:
- User closes the window
WM_CLOSE message gets processed, CloseBrowser(false) gets called, and the close gets canceled by returning 0 in the WinProc
CefLifeSpanHandler::DoClose() gets called, closing flag gets set, and returns false
WM_DESTROY gets processed
What's odd here is that DoClose() is returning false, but another WM_CLOSE message does not seem to be coming to close the window and trigger the OnBeforeClose event.
Here are some details on the design/architecture:
I wrapped the functionality in a dll where I exposed a function called CreateBrowserWindow(), where I give it a parent window handle. This function creates a window using CreateWindowEx (where I give it the parent window handle), and on WM_CREATE of this window I create the browser window and set it as the child by calling CefWindowInfo::SetAsChild(). So here's a summary:
Window A (created in EXE) is parent of Window B (created in dll), which is parent of Window C (browser window). The window proc for window B is in the dll as well.
Miscellaneous info:
multi_threaded_message_loop is set to 1.
Relevent Code Snippets:
WM_CLOSE logic
- Code: Select all
case WM_CLOSE:
if (micefhandler.get() && !micefhandler->IsClosing())
{
CefRefPtr<CefBrowser> browser = micefhandler->GetBrowser();
if (browser.get())
{
// Notify the browser window that we would like to close it. This will result in a call to
// MyHandler::DoClose() if the JavaScript 'onbeforeunload' event handler allows it.
browser->GetHost()->CloseBrowser(true);
//cancel the close
return 0;
}
}
//close allowed
result = DefWindowProc(window_handle, message, w_param, l_param);
break;
CefLifeSpanHandler::DoClose logic
- Code: Select all
bool MICefHandler::DoClose(CefRefPtr<CefBrowser> browser)
{
//Must be executed on the UI thread
CEF_REQUIRE_UI_THREAD();
base::AutoLock lock_scope(lock_);
// Closing the main window requires special handling. See the DoClose()
// documentation in the CEF header for a detailed description of this
// process.
if (m_BrowserId == browser->GetIdentifier())
{
// Set a flag to indicate that the window close should be allowed.
m_bIsClosing = true;
}
return false;
}
Any help is appreciated. Thank you.