Windows: Use WS_EX_NOACTIVATE to control initial window activation (issue #1856)

This commit is contained in:
Marshall Greenblatt
2019-02-07 16:36:31 -05:00
parent 84a5749f9f
commit b8eaec0db2
10 changed files with 107 additions and 7 deletions

View File

@@ -207,8 +207,27 @@ bool CefBrowserPlatformDelegateNativeWin::CreateHostWindow() {
gfx::Rect(0, 0, point.x(), point.y()));
window_widget_ = delegate_view->GetWidget();
const HWND widget_hwnd = HWNDForWidget(window_widget_);
DCHECK(widget_hwnd);
const DWORD widget_ex_styles = GetWindowLongPtr(widget_hwnd, GWL_EXSTYLE);
if (window_info_.ex_style & WS_EX_NOACTIVATE) {
// Add the WS_EX_NOACTIVATE style on the DesktopWindowTreeHostWin HWND
// so that HWNDMessageHandler::Show() called via Widget::Show() does not
// activate the window.
SetWindowLongPtr(widget_hwnd, GWL_EXSTYLE,
widget_ex_styles | WS_EX_NOACTIVATE);
}
window_widget_->Show();
if (window_info_.ex_style & WS_EX_NOACTIVATE) {
// Remove the WS_EX_NOACTIVATE style so that future mouse clicks inside the
// browser correctly activate and focus the window.
SetWindowLongPtr(widget_hwnd, GWL_EXSTYLE, widget_ex_styles);
}
return true;
}