Rank: Advanced Member Groups: Member
Joined: 1/15/2015 Posts: 48
|
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.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
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!
|
Rank: Advanced Member Groups: Member
Joined: 1/15/2015 Posts: 48
|
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.
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,218
|
This makes perfect sense. Thanks for sharing!
|