Page 1 of 1

WebView is always the topmost form

Posted: Wed Sep 14, 2022 1:18 pm
by kopernikus
I am using WebView4Delphi in a child form. "FormStyle" is set to "fsNormal". Nevertheless, the form always remains staying as topmost. Is there a way to change this behavior?

Re: WebView is always the topmost form

Posted: Wed Sep 14, 2022 2:29 pm
by salvadordf
Hi,

This is known issue in WebView2 :
https://github.com/MicrosoftEdge/WebView2Feedback/issues/356
https://github.com/MicrosoftEdge/WebView2Feedback/issues/286
https://github.com/MicrosoftEdge/WebView2Feedback/issues/708

The suggested workaround is to use a browser in "Windowless mode". See the WindowlessBrowser demo for all the details.

The Windowless mode uses the DirectComposition API :
https://docs.microsoft.com/en-us/windows/win32/directcomp/directcomposition-portal

At this moment Delphi doesn't support the DirectComposition API so we have to use the MfPack component available at GitHub :
https://github.com/FactoryXCode/MfPack

Another possible workaround :
CEF has a similar issue and the suggested workaround is to use WS_EX_NOACTIVATE as the window style. I haven't tried this in WebView2 but perhaps you can call SetWindowLongPtr at some point. I'm not sure which handle you should use with SetWindowLongPtr but here you have some possibilities :

Code: Select all

SetWindowLongPtr(Form1.Handle, GWL_EXSTYLE, WS_EX_NOACTIVATE);
SetWindowLongPtr(WVBrowser1.RenderCompHWND, GWL_EXSTYLE, WS_EX_NOACTIVATE);
SetWindowLongPtr(WVBrowser1.D3DWindowCompHWND, GWL_EXSTYLE, WS_EX_NOACTIVATE);
SetWindowLongPtr(WVBrowser1.Widget0CompHWND, GWL_EXSTYLE, WS_EX_NOACTIVATE);
SetWindowLongPtr(WVBrowser1.Widget1CompHWND, GWL_EXSTYLE, WS_EX_NOACTIVATE);
Let us know if you managed to make WS_EX_NOACTIVATE work! :)

Re: WebView is always the topmost form

Posted: Thu Sep 15, 2022 3:46 pm
by kopernikus
Thank you for your advice, but unfortunately the WS_EX_NOACTIVATE does not work with the suggested handles. On the other hand, I had partial success with calling SetWindowPos. I added the following call to the OnActivate event of the main window:

Code: Select all

SetWindowPos(frmWebView.Handle,Handle,0,0,0,0,SWP_NOACTIVATE or SWP_NOMOVE or SWP_NOSIZE);
Now, on activating the the main window, the child window with the web view goes behind
the main window. But this works only as long as you don't click on the TWVBrowser component.

Re: WebView is always the topmost form

Posted: Fri Aug 04, 2023 4:16 pm
by kopernikus
The issue seems to be fixed in WebView 1.0.1901

Re: WebView is always the topmost form

Posted: Sat Aug 05, 2023 2:46 pm
by kopernikus
The issue seems to be fixed in WebView2 version 1.0.1901.177