Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

How to start SimpleBrowser.exe without losing the focus?

Post Reply
wolf
Posts: 22
Joined: Thu Jan 31, 2019 6:36 pm

How to start SimpleBrowser.exe without losing the focus?

Post 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
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

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

Post 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.
wolf
Posts: 22
Joined: Thu Jan 31, 2019 6:36 pm

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

Post 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.
Post Reply