cefsharp / CefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework
http://cefsharp.github.io/
Other
9.87k stars 2.92k forks source link

WinForms - CreateBrowser Forcing form activation #1811

Closed Hyrius closed 5 years ago

amaitland commented 8 years ago

Needs to be fixed in CEF. Search the CEF issue tracker, there is already an open issue for this.

amaitland commented 8 years ago

https://bitbucket.org/chromiumembedded/cef/issues/1856/branch-2526-cef-activates-browser-window

amaitland commented 5 years ago

Has finally been fixed in CEF, see commit https://bitbucket.org/chromiumembedded/cef/commits/db143a568876175974e9abed4817f989af23f5d3 for details.

https://github.com/cefsharp/CefSharp/blob/cefsharp/71/CefSharp.WinForms/ChromiumWebBrowser.cs#L644

amaitland commented 5 years ago

I will likely make WS_EX_NOACTIVATE the default and allow for customisation of IWindowInfo like in WPF. Anyone wishing to still use the default behaviour will be able to, though it doesn't really make much sense for it to be the default to me.

https://github.com/cefsharp/CefSharp/blob/cefsharp/71/CefSharp.Wpf/ChromiumWebBrowser.cs#L1773

amaitland commented 5 years ago

WS_EX_NOACTIVATE was made the default in https://github.com/cefsharp/CefSharp/commit/a7a73dc930f1ee2f39c40a170e9f795247b3e4e6

To re-enable activation by default then create a custom class that inherits from ChromiumWebBrowser and override the CreateBrowserWindowInfo method. Then it's a simple case of removing WS_EX_NOACTIVATE from WindowInfo.ExStyle

const uint WS_EX_NOACTIVATE = 0x08000000;

windowInfo.ExStyle &= ~WS_EX_NOACTIVATE;

If there is enough demand then I will add a bool Property that can be used to enable/disable activation. It's not clear that there is enough demand at the moment, most people asking how to disable window activation as it's an unexpected behaviour.

arcanisgk commented 2 years ago

Any Example of implementation in C# winform ???