Jump to content

IEAttach embedded problems


rdellis
 Share

Recommended Posts

I have a IE browser embedded in a windows application.

I can't get the following IEAttach script to work, it returns an error code 7.

$handle = WinActivate("MyAppTitle")

$oIE = _IEAttach("MyAppTitle", "embedded", 1)

This also fails:

$handle= ControlGetHandle("MyAppTitle", "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")

If I manually place in the Control handle id, the following works great, but the handle is always changing.

$oIE = __IEControlGetObjFromHWND("0x000805C6")

Surprisingly if I place a msgbox in the code and remove the IEAttach title, IEAttach will work most of the time. Leaving the title in the IEAttach will return an error code of 7.

$handle = WinActivate("MyAppTitle")

MsgBox(0,"Handle",$handle)

$oIE = _IEAttach("", "embedded", 1)

I need to be able to attach to the embedded IE browser consistantly without using a msgbox.

Link to comment
Share on other sites

Since you have the handle of the parent window, use it:

$hWin = WinActivate("MyAppTitle")
If $hWin Then
     $oIE = _IEAttach($hWin, "embedded", 1)
Else
     MsgBox(16, "Error", "Window not found.")
     Exit
EndIf

:graduated:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

$hWin = WinActivate("MyAppTitle")

If $hWin Then

$oIE = _IEAttach($hWin, "embedded", 1)

Else

MsgBox(16, "Error", "Window not found.")

Exit

EndIf

In your example I get back a good handle from WinActivate, but _IEAttach throws an error code of 7 ("No Match").

$oIE = _IEAttach($hWin, "embedded", 1) ;does not work - error code of 7 ("No Match").

$oIE = _IEAttach("MyAppTitle", "embedded", 1) ;does not work - error code of 7 ("No Match").

MsgBox(0,"Error","test")

$oIE = _IEAttach("", "embedded", 1) ;this works, but left with msgbox

Link to comment
Share on other sites

  • 1 month later...

I don't understand why your MsgBox call would have any bearing... do you?

Does the AutoIt Window Info tool shed any light?

Dale

Edited by DaleHohm

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

Link to comment
Share on other sites

Dale, I don't understand why the msgbox would allow the IEAttach function to work most of the time. But without it I can not attach to the embedded IE page unless I use the IE page handle. I have used the AutoIT window info tool to get the handle and everything works great when I reference the IE page by handle. But I have not figured out how to get the handle of the embedded IE page programmatically.

I used the AutoIT window info tool to get the IE page CLASS to try:

$handle= ControlGetHandle("MyAppTitle", "", "[CLASS:Internet Explorer_Server; INSTANCE:1]")

No success here.

I have explored the AutoIT window info tool looking for anything I could use and tried several option, but came up with nothing. Anything else I should try with the AutoIT window info tool?

Link to comment
Share on other sites

The only thing that makes sense to me as t wy the MsgBox would affect anything is that yu have timing issue. Try puting your attach logic in a retry loop with a delay and see if ieventually works. Ifi does, you can look at more surgical methods of sensing when the object is available.

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

Link to comment
Share on other sites

Dale, placing the code in a timing loop did not help. Except for another bizzare occurrence. I noticed if I minimized the AutoIT Info Window while in the timing loop, the IEAttach would work. I tried the same thing with task manager and got the same positive results.

It now appears the IEAttach embedded will only work if the window is active.

This should active the window:

WinActivate("MyAppTitle")

and this should confirm the window is active:

WinActive("MyAppTitle")

Although both come back successful, the window is not active. Clicking on the application window during the timing loop will also bring back a successful IEAttach. This explains the msgbox working. After clicking OK on the message box, the application window gets focus.

Why the application is not getting focus after the WinActivate("MyAppTitle") command is confusing me and why WinActive reports that the application has focus when it doesn't.

Here is my code:

AutoItSetOption("WinTitleMatchMode",1)

$hwnd=WinActivate($MyAppTitle)

If $hwnd=0 Then

MsgBox(16,"Error","Error activating window")

Exit

EndIf

If WinActive($MyAppTitle)=0 Then

MsgBox(16, "Error", "Window not active")

Exit

EndIf

Opt("SendKeyDelay",250)

Send("{F10}")

For $i = 1 to 30

Sleep(250)

$oIE=_IEAttach("","embedded",1)

If @error=0 Then

ExitLoop

EndIf

Next

If @error>0 Then

MsgBox(16,"Error","Error ("&@error&") connecting to embedded IE window.")

Exit

EndIf

Link to comment
Share on other sites

AutoItSetOption("WinTitleMatchMode",3) appears to fix my window focus problem. Match mode 1 & 2 would not leave the window active.

Still seems strange the following statement does not work:

$oIE=_IEAttach($MyAppTitle,"embedded",1)

I have to use:

$oIE=_IEAttach("","embedded",1)

Dale, thanks for your help.

Link to comment
Share on other sites

Does the window title change when it has focus?

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

Link to comment
Share on other sites

No. Apparently there is a component within the application with the title $MyAppTitle & " Message Window". WinActivate, WinActive, and IEAttach were apparently all attaching to this internal app component and not the main application. Whenever a msgbox was dispatched, the main application window got focus and not the component within the application and things would work.

AutoItSetOption("WinTitleMatchMode",3) allows an exact match on $MyAppTitle, thus solving the problem of connecting to $MyAppTitle & " Message Window".

$oIE=_IEAttach("","embedded",1) is now working, but if for whatever reason my application is not the active window this command will fail.

$oIE=_IEAttach($MyAppTitle,"embedded",1) would certainly be better.

Link to comment
Share on other sites

I'm afraid I'd need a reproducer to help further.

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

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...