Better alternative to appactivate? (nice easy points for the experts!)

Lostie
Lostie used Ask the Experts™
on
Hi Experts,

Before I outline the problem, I should point out that I'm using Attachmate Extra! basic, which is a cut-down version of Microsoft VB. Feel free to post any VB solutions though, I *may* be able to adapt and use them.

Right, I'm using Internet Explorer's DOM to automate some tasks on various websites, one of which is to do a google search. Code so far:

Dim IE as Object
Set IE=CreateObject("Internetexplorer.Application")
IE.visible=true
IE.navigate("http://www.google.co.uk/")
call IEwait
Appactivate "Google - Microsoft Internet Explorer"
x=ShowWindow(IE.hwnd, 3) '### Maximise window ###

Is there a way to use the IE.hwnd object to perform something like appactivate on it? I've already got it maximised using the IE.hwnd object as you can see above, but maximising does not bring it into focus hence the need for appactivate. I need to use this code on other websites whose windows will have changing titles instead of always being "Google - Microsoft Internet Explorer" - which is why I'd much rather use a better solution than appactivate. Anyone?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2006
Commented:
use the API

Public Declare Function SetActiveWindow Lib "user32" Alias "SetActiveWindow" (ByVal hwnd As Long) As Long

like this

Dim IE as Object
Set IE=CreateObject("Internetexplorer.Application")
IE.visible=true
IE.navigate("http://www.google.co.uk/")
call IEwait
' Appactivate "Google - Microsoft Internet Explorer"
x=SetActiveWindow(IE.hwnd)
x=ShowWindow(IE.hwnd, 3) '### Maximise window ###

hope this helps a bit see also the setfocus and setforegroundwindow calls

title :http://www.mentalis.org/apilist/SetActiveWindow.shtml
source : http://www.mentalis.org/apilist/SetActiveWindow.shtml

Author

Commented:
setfocus() didn't do what I wanted, but setforegroundwindow worked perfectly. Thanks again :-)
Top Expert 2006

Commented:
you're welcome, thanks for the grade :)
Top Expert 2006

Commented:
hmm... thanks,

Cd& is right and i'm trying to let his wisdom guide me and get those high point questions down it's not working yet :)

thanks Lostie and Lunchy too

Commented:
I also had this problem - but as I was doing it in VBScript I couldnt use this above solution.
My solution uses AppActivate - but before it I change the title of the IE to a specific string:

  Set ie = WScript.Createobject("internetExplorer.application", "event_")
  ie.visible = true
  ie.document.title = "tmp123"
  WshShell.AppActivate("tmp123")

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial