Page 1 of 1

How to start SimpleBrowser.exe without losing the focus?

Posted: Thu Jan 31, 2019 6:39 pm
by wolf
Is it possible to start an EXE (with mainform + Chromium browser) without activating the window?

With other Delphi based EXEs I use ShellExecute with SW_SHOWNOACTIVATE and the calling EXE keeps the focus.

When I launch SimpleBrowser.exe from the demo applications, then SimpleBrowser gets the focus and the calling EXE loses the focus.

This is how I call the SimpleBrowser:

Code: Select all

ShellExecute(Self.Handle, nil, PChar('c:\test\SimpleBrowser.exe'), nil, PChar('c:\test\'), SW_SHOWNOACTIVATE);
My main goal is that the calling EXE keeps the focus.
Any chance to get this working?

Thanks,
Wolf

Re: How to start MiniBrowser.exe without losing the focus?

Posted: Thu Jan 31, 2019 7:27 pm
by salvadordf
Hi,

I did a quick search and there seems to be 2 unresolved focus issues in CEF3 :
https://bitbucket.org/chromiumembedded/ ... ion-to-the
https://bitbucket.org/chromiumembedded/ ... ser-window

There are several suggestions in the official CEF3 forum but some people say that they could avoid this problem using the LockSetForegroundWindow Windows API function :
https://docs.microsoft.com/en-us/window ... oundwindow

Try calling LockSetForegroundWindow with a LSFW_LOCK parameter before the ShellExecute call. After that, call LockSetForegroundWindow with a LSFW_UNLOCK parameter.

In case that didn't work I would also try this :
  • Set the CEFWindowParent1.TabStop to FALSE and reorder the TabOrder properties in the browser form. Set another control as the first to get the focus.
  • Use the TChromium.OnSetFocus event and set the "Result" parameter to TRUE.
In the rare case where all that fails you can also override TCEFWindowParent.WndProc and intercept WM_SETFOCUS to ignore it and set the focus back to your application.

Re: How to start SimpleBrowser.exe without losing the focus?

Posted: Thu Jan 31, 2019 9:02 pm
by wolf
Thank you very much for your help!

LockSetForegroundWindow works great.

I could not get it working with the other suggestions, but LockSetForegroundWindow works perfectly well.