Jump to content

Embedded IE Object Steals Focus


Recommended Posts

I'm currently working on a project that uses an embedded IE object in the background, that continually navigates to several different pages while gathering data. The problem is each _IENavigate() function steals the focus from all other controls, and even GUI windows. I've read the forums and haven't found a fix for the issue, so here I am trying to start another thread.

Below is my sample script that reproduces the issue. Just try focusing on the input box while the hidden IE object continually navigates to Google.

#include <IE.au3>
$frm_Main = GUICreate("Can't Keep Focus", 100, 50, 100, 100)
GUISetState(@SW_SHOW, $frm_Main)
$inp_Text = GUICtrlCreateInput("", 10, 10, 70, 20)
$frm_Secondary = GUICreate("Keep Stealing Focus", 500, 500, 600, 100)
$o_Explorer = _IECreateEmbedded()
GUICtrlCreateObj($o_Explorer, 0, 0, 500, 500)
While 1
_IENavigate($o_Explorer, "www.google.com")
WEnd

Is there any work arounds for this? Grabbing the HTML source doesn't work as I need to navigate to the page so I can automate several buttons, input boxes, and combo boxes on each page visited. This seems to only be accomplished by an embedded IE object.

Link to comment
Share on other sites

I'm not sure there will be a "fix", as that implies its abnormal behavior in the first place, which it is not.

My advice is to give focus to the control you want to have it, when/if it needs it.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

If that were possible I would definitely do that. However, the project I've developed is basically a monitor / screen scraping application that automates redundant tasks. I basically have a list view that is updated with information as IE navigates through the different pages. I'm still experimenting with embedded IE windows so I wasn't aware that this is normal behaviour, and figured it was something missed on my part. Now I'm looking for workarounds that might hide the focusing issue.

Link to comment
Share on other sites

I hope you have considered not using embedded IE but regular IE.

#include <IE.au3>
$frm_Main = GUICreate("Can't Keep Focus", 100, 50, 100, 100)
GUISetState(@SW_SHOW, $frm_Main)
$inp_Text = GUICtrlCreateInput("", 10, 10, 70, 20)
$o_Explorer = _IECreate("", 0, 0)
While 1
_IENavigate($o_Explorer, "www.google.com")
WEnd

Embedded IE implies visibility because that's what it's designed for. There is a hidden mode for regular IE and that works like you expected.

TLDR you were doing something thats not intended because theres a better way

Link to comment
Share on other sites

... The problem is each _IENavigate() function steals the focus from all other controls, and even GUI windows.

#include <IE.au3>
;...
While 1
_IENavigate($o_Explorer, "www.google.com")
WEnd

Here is the problem. This is trying to navigate every millisecond over, and over and over again.

This will never work in a continuous loop. You will need to change this

8)

NEWHeader1.png

Link to comment
Share on other sites

Here is the problem. This is trying to navigate every millisecond over, and over and over again.

This will never work in a continuous loop. You will need to change this

8)

Well, this is not true. IENavigate by default waits until the page is completely loaded, so there is quite a lot of Sleep(..) going on there. Beside that, it's not the problem, since he needs to navigate even just once without it stealing focus.
Link to comment
Share on other sites

@ Valuater - Right. That script was basically written with as little code as possible to show the embedded object stealing focus. My normal code runs timers using TimerInit() & TimerDiff() to refresh regularly while allowing the GUI loop to offer user control.

@ Manadar - I never thought about using just a hidden IE window because I was so stuck on the embedded object. My fear when starting with the IE.au3 include was someone accidentally killing their IE task and throwing the whole app off. But now that I'm more comfortable I could just have it check to see if the window still exists, and if not, open it. What method do you suggest using for the hidden IE windows? I'm going to poke around the IE.au3, but who knows, there might be a better way that I'm just overlooking or have no idea about.

Edit- Wanted to say thanks for the responses too.

Edit2- Overlooked Manadar's revised code. So I'm guessing _IECreate() is the route to go. Since this works with the IE.au3, switching the code over shouldn't be too difficult. Thanks again for the responses.

Edited by IAmTheManYo
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...