Sign in to follow this  
Followers 0
Sticky

Unable to get _IEAttach to get object using HWND

8 posts in this topic

I recently posted this: http://www.autoitscript.com/forum/index.php?showtopic=100146&st=0&p=716685&#entry716685

Which was answered by this post: http://www.autoitscript.com/forum/index.php?showtopic=99234&st=0&p=716686&#entry716686

Thanks zackrspv and Dale!

However, I ran into a problem after trying to attach to the newly created instance of IE in kiosk mode. Here is my code:

$pidMVNO = Run(@ProgramFilesDir&"\internet explorer\iexplore.exe -k ", "", @SW_HIDE)
$hwndMVNO = _ProcessGetHWnd($pidMVNO)
While $hwndMVNO = 0 ;Make sure I have an actual handle to give to _IEAttach
    Sleep(50)
    $hwndMVNO = _ProcessGetHWnd($pidMVNO)
WEnd
$MvnoIE = _IEAttach($hwndMVNO, "HWND")

Here is the _ProcessGetHWnd Function, (found in the second linked post above):

Func _ProcessGetHWnd($iPid, $iOption = 1, $sTitle = "", $iTimeout = 2000)
    Local $aReturn[1][1] = [[0]], $aWin, $hTimer = TimerInit()
    While 1
      $aWin = WinList($sTitle)
        For $i = 1 To $aWin[0][0]
            If $iPid = WinGetProcess($aWin[$i][1]) Then
                If $iOption = 1 OR ($iOption = 0 And $aWin[$i][0] <> "") Then
                    Return $aWin[$i][1]
                ElseIf $iOption = 2 Then
                    ReDim $aReturn[UBound($aReturn) + 1][2]
                    $aReturn[0][0] += 1
                    $aReturn[$aReturn[0][0]][0] = $aWin[$i][0]
                    $aReturn[$aReturn[0][0]][1] = $aWin[$i][1]
                EndIf
            EndIf
        Next
        If $iOption = 2 And $aReturn[0][0] > 0 Then Return $aReturn
        If TimerDiff($hTimer) > $iTimeout Then ExitLoop
        Sleep(Opt("WinWaitDelay"))
    WEnd
       SetError(1)
    Return 0
EndFunc  ;==>_ProcessGetHWnd

The error I receive is:

--> IE.au3 V2.4-0 Warning from function _IEAttach, $_IEStatus_NoMatch

What am I doing wrong?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I also tried using the undocumented __IECreateNewIE function in IE.au3 to automatically get the object reference and use that to navigate to the sites I needed, but had to have it in kiosk mode. I added the -k and it worked but it would not attach the IE instance to my GUI, it was just full screen. Any ideas?

Edited by Sticky

Share this post


Link to post
Share on other sites

I don't see you checking your return value with isHWND(). Also try doing onter things to the window you think you found, like a Flash(), to insure it is what you expect.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Thank you for the window flash suggestion as the it doesn't work when passing the handle to it.

I also manually verified the PID with tasklist in command prompt. I noticed that when first running IE, it opens up two iexplore processes and my script picks up the first one which does successfully get a handle but does not attach as an IE object.

I used an input call in my script right after it picks up the first pid and manually entered the second pid but this had the same results.

So even though it gets a handle, it is unable to flash the window using the first or second pid.

By the way, what I'm trying to accomplish here is due to the fact that embedding IE more than once causes a known bug which keeps the keyboard focus only on one instance, but this seems to be "work-aroundable" by having full instances of IE in kiosk mode instead.

For $i = 0 to $browsers - 1 ;browsers variable is 2 at the moment
    $IEpid[$i] = Run(@ProgramFilesDir&"\internet explorer\iexplore.exe about:blank", "")
    $pidFound = False
    While $pidFound = False
        $iexplore = WinList()
        For $j = 1 To $iexplore[0][0]
            If $IEpid[$i] = WinGetProcess($iexplore[$j][1]) Then
                MsgBox(0, "Found", $IEpid[$i]) ;I show the pid so I can verify it in the tasklist
                If IsHWnd($iexplore[$j][1]) Then ;it always passes this test
                    $IEhwnd[$i] = $iexplore[$j][1]
                    _WinAPI_FlashWindow($IEhwnd[$i]) ;this does not flash the window, I've tried minimizing it first as well
                    $oIE[$i] = _IEAttach($IEhwnd[$i], "hwnd") ; never matches
                    $pidFound = True
                    ExitLoop
                Else
                    MsgBox(0, "", "Not HWnd")
                EndIf
            EndIf
        Next
    WEnd
    
    _WinAPI_ShowWindow($IEhwnd[$i], @SW_HIDE)
    _IENavigate($oIE[$i], $urls[$i], 0) ;this of course throws an error since it was not attached properly
Next

Share this post


Link to post
Share on other sites

I'm still stuck on this...

I don't know how to go any further unless I make an IE window show up and go to a specific webpage, then grab the instance based on the title, then hide it, and then start over except direct the next instance to a different specific webpage with a different title...

Seems very ineffecient and unprofessional with windows popping up and dissappearing and all

Share this post


Link to post
Share on other sites

Welp, I went ahead and did it with windows popping up and disappearing except I set the the main GUI to visible and WinSetOnTop to true before creating the IE instances, which simply causes a slight flicker in your start bar. This seems to have solved all of my problems.

Also, since _IECreate() creates an object, I couldn't find a way to enable Kiosk mode, but did find the TheaterMode property in Dale's MSDN IE Object link. This allows for users to still use the menu bar by hovering near the top. The only catch being that hitting F11 will cause the window to show the title bar and everything, regardless of the _WinAPI calls made earlier.

WinSetOnTop("Logon Utility - Current User: ", "", 1)
For $i = 0 to $browsers - 1
    $oIE[$i] = _IECreate()
    _IEAction($oIE[$i], "invisible")
    $oIE[$i].TheaterMode = 1
    $IEhwnd[$i] = _IEPropertyGet($oIE[$i], "hwnd")

    _WinAPI_SetParent($IEhwnd[$i], $hGUI)
    _WinAPI_MoveWindow($IEhwnd[$i], 140, 0, 792, 634, True)
    _WinAPI_SetWindowLong($IEhwnd[$i], $GWL_STYLE, $WS_POPUP)
Next

Share this post


Link to post
Share on other sites

Sorry, my forum settings were making me miss some replies like yours.

Please see here: http://www.autoitscript.com/forum/index.php?showtopic=101546&view=findpost&p=722986

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Sorry, my forum settings were making me miss some replies like yours.

Please see here: #722986

Dale

That's ok! It seems I came up with a similar solution as create new IE instances using your UDF, then put them in Theater mode and hide them.

My GUI is also resizable, so I have each IE instance moving and resizing based on the Resize, Maximize, and Minimize events.

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