Logo
My Account |  Site Map | Contact Us  
Welcome Guest Search | Active Topics | Sign In | Register

Web Browser Form Control Steals Focus Options
KSystems
Posted: Wednesday, September 4, 2019 7:04:37 PM
Rank: Advanced Member
Groups: Member

Joined: 1/15/2015
Posts: 34
We have a Windows Forms app that uses EO Web Browser control, and it listens for JS events from our web application. When an event is received it will bring the form window to the front, and if the window was minimized at the time it will change the WindowState to Normal. It will basically pop up the window.

We don't want this window to interrupt the user if they are typing, however, after some testing it seems the EO Web Browser is stealing focus. We have overridden the "ShowWithoutActivation" to always be true for the main form, and when EO Web Browser is not on the form, or Enabled = false, it works great. If it is on the form, or Enabled = true, the web browser control steals focus. So someone typing in notepad for example will be interrupted.

We have also did some tests and found that setting Control.Enabled = false for the EO Web Browser, then popping the window up, then setting it back to true works sometimes, but its a hack, and doesn't work all the time due to timing issues.

We also tried enabling and disabling the control based on GotFocus and LostFocus events but that also is somewhat hacky and was hit or miss.

We also tried some native ShowWindow function using SW_SHOWNOACTIVATE flag and that doesn't work either.

Is there any setting we might have overlooked that can disable the EO Web Browser automatically getting focus when shown or on window state change?

Thanks for your help.
eo_support
Posted: Thursday, September 5, 2019 10:02:51 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,568
Hi,

The WebControl does not monitor any windows activation event and change focus. Windows Forms is doing that part (As a test, you can try to replace the WebControl with a simple TextBox and see if you see the same issue). When the form is activated, Windows Forms will give focus to the last known focused control in the form, or if non exists, it will give focus to the first focusable control in the form. If that control happens to be the WebControl, then the WebControl takes over and places focus on the first focusable element in the document (such as a textbox in the web page). But it won't do anything unless the focus is already passed to the WebControl first - - - this part is not something that can be stopped by the WebControl.

Thanks!
KSystems
Posted: Friday, September 6, 2019 5:59:24 PM
Rank: Advanced Member
Groups: Member

Joined: 1/15/2015
Posts: 34
Thank you for your quick reply.

After further review with your reply in consideration, it seems maybe there is a bug in Windows. The normal flow is to "activate" the window and then it will "focus" on any control within as you said. So we figured if we just prevent the "activate" from happening the "focus" wouldn't happen either. However, that didn't seem to work anymore (it did work in the past).

We are using User32.ShowWindow() with SW_SHOWNOACTIVATE to show the window without activating but it seems there is some bug where something else is activating for some reason. We used Spy++ to see the WM_ACTIVATE messages being sent.

We ended up hooking into WndProc and just capturing the windows messages directly when we didn't want the activation and focus to take place. Something very similar to this but with more conditions:

Code: C#
private const int WM_ACTIVATE = 0x0006;
private const int WM_SETFOCUS = 0x0007;
protected override void WndProc(ref Message msg)
{
      if (msg.Msg == WM_SETFOCUS || msg.Msg == WM_ACTIVATE)
      {
          return;
      }
      base.WndProc(ref msg);
}


Thanks for the assistance.
eo_support
Posted: Monday, September 9, 2019 9:51:47 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 21,568
This makes perfect sense. Thanks for sharing!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.