Geeks With Blogs

News QTP and Stuff
Theo Moore Questions... Morphology? Longevity? Incept dates?

Partha, a gentleman who posted on my blog, left some suggestions that ultimately made getting the page and browser hwnd much easier. I made some slight changes to his code to do what  I wanted, and here's our result:

Public Function OpenBrowser(byval URL,ByRef strBrowser, ByRef strPage) 
 Dim oIE   'As InternetExplorer.Application
 Dim WaitCount   'As Long

 Set oIE = CreateObject("InternetExplorer.Application")
 oIE.visible = 1
 oIE.Navigate2 URL

 WaitCount = 0
 Do While oIE.ReadyState <> 4 And WaitCount < 5

 If oIE.ReadyState <> 4 Then
  OpenBrowser = False
  Exit Function
 End If

 strBrowser = "hwnd:=" & oIE.hwnd
 strPage = "hwnd:= " & CStr(Browser("hwnd:=" & oIE.hwnd).Page("title:=" & oIE.Document.Title).GetROProperty("hwnd"))
 OpenBrowser = True
End Function


Getting at the IE instance hwnd is simple, and I was all over that. However, I was looking for the page handle with EnumChildWindows API calls. It worked, and worked well. However, the solution suggested to get at it via:B

Browser("hwnd:=" & oIE.hwnd).Page("title:=" & oIE.Document.Title).GetROProperty("hwnd")

was much more eloquent. Good call, Partha.

Posted on Thursday, May 4, 2006 2:53 PM | Back to top

Comments on this post: QTP: Browser and page handles; a better solution

Comments are closed.
Comments have been closed on this topic.
Copyright © Theo Moore | Powered by: