TChromiumwindow behind parent FORM

Post Reply
jlp
Posts: 3
Joined: Tue Mar 19, 2019 8:50 am

TChromiumwindow behind parent FORM

Post by jlp » Tue Mar 19, 2019 9:16 am

Hi all! I have just started using CEF4D because I want to show a webpage on my delphi 7 application. The app is SDI with dialogs.

Consider FORM A as main form (really big form with so many code).
Inside FORM A I create FORM B that has an object chromiumwindow inside to display webpages.
The problem is when showing FORM B if I click outside FORM B (ie another windows application), then when clicking back to FORM B, it stays behind FORM A. ¿¿??

- I have tried using TChromium with TCEFLinkedWindowParent without luck.
- I have tried using ONGOTFOCUS to handle focus without luck.

The partial solution is to set FORM B as TOPMOST window then it works.

The problem with this is that if FORM B is created with ShowMODAL then it doesnt work as expected and when FORM B is shown and then we click outside application when returning; FORM A is in front and you can make nothing to "reactivate" the application because FORM B is modal but you can not click any elements because FORM A is at front.


This problems only occur when clicking inside TCHROMIUMWINDOW control If I click FORM B but not over TCHROMIUMWINDOWS it all works ok, so it seems like when TCHROMIUMWINDOW is clicked strange things happen.


And now the FULL SOLUTION... just added this piece of code to FORM B and all works as expected.

procedure TECP_GUI.ChromiumWindow1AfterCreated(Sender: TObject);
begin
SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);
end;

Any thoughts about this?
Last edited by jlp on Tue Mar 19, 2019 11:42 am, edited 1 time in total.

User avatar
salvadordf
Posts: 2504
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromiumwindow behind parent FORM

Post by salvadordf » Fri Mar 22, 2019 2:27 pm

Hi,

First of all, sorry for the long delay.

I only have a Delphi Community Edition license and I can't test Delphi 7.

I tried to reproduce this issue in Delphi 10.3 and Lazarus using the toolbox demos but I couldn't get the same results.

CEF also had some focus issues like this one :
https://bitbucket.org/chromiumembedded/cef/issues/1856/branch-2526-cef-activates-browser-window

It was fixed using a WS_EX_NOACTIVATE exstyle :
https://bitbucket.org/chromiumembedded/cef/commits/b8eaec0db2497939b3eca3e186d259cfa9a77ed7?at=master

I'm not sure if this is related to this issue but I would try to modify TChromium.InitializeWindowInfo and call WindowInfoAsChild with the aExStyle parameter :

Code: Select all

WindowInfoAsChild(FWindowInfo, aParentHandle, aParentRect, aWindowName, WS_EX_NOACTIVATE);

jlp
Posts: 3
Joined: Tue Mar 19, 2019 8:50 am

Re: TChromiumwindow behind parent FORM

Post by jlp » Fri Mar 22, 2019 7:11 pm

Thanx for your reply. I'll give a shot on your ideas.
Last edited by jlp on Mon Mar 25, 2019 11:07 am, edited 1 time in total.

jlp
Posts: 3
Joined: Tue Mar 19, 2019 8:50 am

Re: TChromiumwindow behind parent FORM

Post by jlp » Mon Mar 25, 2019 9:41 am

Hi Salvador. I have tested the piece of code you said but it made no difference.
WindowInfoAsChild(FWindowInfo, aParentHandle, aParentRect, aWindowName, WS_EX_NOACTIVATE);

In the other hand I tested ToolBoxBrowser on delphi 7 and is working as expected without issues.
After this test I have pointed my "FORM A" to create one of this "TChildForm". The result?
Exactly the same as with my code... TChildForm goes behind parent when clicking outside of the application.

To find exactly where the problem is (Delphi 7? Chromium newest engine? CEF4Delphi?) I should compact the code of my program to the minimum expression or build some test cases that show this issue... but this would require time.

At this time, I will continue using
"SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE); "
as it solve my problems.


Thanx for your time.

PS: Just for curiosity... using "https://github.com/hgourvest/dcef3, Branch Master, Latest commit 91fdebb on 11 Jun 2016" it works ok. O_o

BBC
Posts: 7
Joined: Tue Feb 27, 2018 11:38 am

Re: TChromiumwindow behind parent FORM

Post by BBC » Sat Aug 01, 2020 4:29 pm

SetWindowPos(Handle, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOSIZE or SWP_NOMOVE);

WindowInfoAsChild(FWindowInfo, aParentHandle, aParentRect, aWindowName, WS_EX_NOACTIVATE);

TChromium.DefaultWindowInfoExStyle := WS_EX_NOACTIVATE;

Not help me =\

if PostMessage(...WM_LBUTTONDOWN.... Chromium steals focus....

Pls help!

User avatar
salvadordf
Posts: 2504
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: TChromiumwindow behind parent FORM

Post by salvadordf » Sat Aug 01, 2020 6:14 pm

I'm sorry but that's a known unreloved issue in CEF.

If those workarounds don't help you then consider using a browser in "Off-screen" mode, also known as OSR mode.

The OSR mode gives you total control of the focus. Try the SimpleOSRBrowser demo.

Post Reply