Sign in to follow this  
Followers 0
BobbyBao

Help! $oIE.Blur() Error

8 posts in this topic

#1 ·  Posted (edited)

Hello guys,

I am a beginner of AutoIt, but have become an AutoIt lover :)

I'v written some simple code about opening a new IE window and losing focus subsequently:

$oIE = _IECreate($url)

_IELoadWait ($oIE, 0, 10000)

$oIE.Blur()

but an error appears as below:

==> The requested action with this object has failed.:

$oIE.Blur()

$oIE.Blur()^ ERROR

>Exit code: 1 Time: 16.601

I have tried the function _IEAction($oIE, "blur") as well which caused the same error.

Can anybody know how to fix problem up? Thanks!

Bobby

Edited by BobbyBao

Share this post


Link to post
Share on other sites



Welcome to the forums.

I'm not sure how you are meant to loose focus to the whole window like that, but maybe you should try WinSetState? Blur should only work on a control object, if my understanding of it is correct.

If you want to start it hidden just use the following _IECreate line by changing $f_visible to = 0. Like so:

_IECreate ("www.autoitscript.com", 1, 1, 0)

Cheers,

Brett

Share this post


Link to post
Share on other sites

Welcome to the forums.

I'm not sure how you are meant to loose focus to the whole window like that, but maybe you should try WinSetState? Blur should only work on a control object, if my understanding of it is correct.

If you want to start it hidden just use the following _IECreate line by changing $f_visible to = 0. Like so:

_IECreate ("www.autoitscript.com", 1, 1, 0)

Hi Brett,

Thank you for that quick response :)

Sorry if I'm being a bit dense...

I just want to open up a new IE window at background without getting focus rather than hidding it. The focus should only be left on my current working stuff. Is there any better way to do that?

Regards,

Bobby

Share this post


Link to post
Share on other sites

I'm not sure that you can do that directly with AutoIt...

Although you could inject some javascript into the page to make it a pop-behind window.

http://javascript.internet.com/page-details/go-behind-popup.html

Share this post


Link to post
Share on other sites

Hows this go for you?

#include <IE.au3>
#Include <Array.au3>
$iPID = -1
$sURL = "www.google.com"
$old_list = ProcessList ("iexplore.exe")

$oIE = _IECreate ($sURL)

$new_list = ProcessList ("iexplore.exe")

For $i = 1 to $new_list[0][0]
    $afound = _ArraySearch ($old_list, $new_list[$i][1])
    If @error Then
        $iPID = $new_list[$i][1]
        ExitLoop
    EndIf
Next

$hWnd = _GetHwndFromPID($iPID)

;MINIMIZE
WinSetState($hWnd, "", @SW_MINIMIZE)

Func _GetHwndFromPID($PID)
    $hWnd = 0
    $winlist = WinList()
    Do
    For $i = 1 To $winlist[0][0]
    If $winlist[$i][0] <> "" Then
    $iPID2 = WinGetProcess($winlist[$i][1])
    If $iPID2 = $PID Then
    $hWnd = $winlist[$i][1]
    ExitLoop
    EndIf
    EndIf
    Next
    Until $hWnd <> 0
    Return $hWnd
EndFunc;==>_GetHwndFromPID

Share this post


Link to post
Share on other sites

Hows this go for you?

#include <IE.au3>
#Include <Array.au3>
$iPID = -1
$sURL = "www.google.com"
$old_list = ProcessList ("iexplore.exe")

$oIE = _IECreate ($sURL)

$new_list = ProcessList ("iexplore.exe")

For $i = 1 to $new_list[0][0]
    $afound = _ArraySearch ($old_list, $new_list[$i][1])
    If @error Then
        $iPID = $new_list[$i][1]
        ExitLoop
    EndIf
Next

$hWnd = _GetHwndFromPID($iPID)

;MINIMIZE
WinSetState($hWnd, "", @SW_MINIMIZE)

Func _GetHwndFromPID($PID)
    $hWnd = 0
    $winlist = WinList()
    Do
    For $i = 1 To $winlist[0][0]
    If $winlist[$i][0] <> "" Then
    $iPID2 = WinGetProcess($winlist[$i][1])
    If $iPID2 = $PID Then
    $hWnd = $winlist[$i][1]
    ExitLoop
    EndIf
    EndIf
    Next
    Until $hWnd <> 0
    Return $hWnd
EndFunc;==>_GetHwndFromPID

#include <IE.au3>

$sURL = "www.google.com"

$oIE = _IECreate ($sURL)
$hWnd = _IEPropertyGet($oIE, "hwnd")

WinSetState($hWnd, "", @SW_MINIMIZE)

Share this post


Link to post
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
Sign in to follow this  
Followers 0