Search here for all the info you want in this Blog

What is HWND, how to use it in QTP and vbscript to handle windows and internet explorer.


hWND breaks up into h+ WND = handle +Windows. You can reference a window through its handle.

Here is a nice definition of hWND:

A window handle (usually shortened to hWnd) is a unique identifer that Windows assigns to each window created. By window in this case we are referring to everything from command buttons and textboxes, to dialog boxes and full windows.


'hwnd' is a property of an object, just like name/title.

"Browser("index:=0").GetROProperty("hwnd")"

This line of code will retrive the value of "hwnd" property for the Browser with index 0. (i.e. the first browser that was opened.)
Using this property you can then perform actions on that particular browser.

try to execute this code...
Open a notepad file before executing the code.

' Get the hwnd value for the notepad into a variable.
val_hwnd = Window("Notepad").GetROProperty("hwnd")
msgbox val_hwnd

' Perform action on the notepad whose hwnd value matches with the captured one.
SystemUtil.CloseProcessByHwnd (val_hwnd)

I am using the following code for Minimize window:
hwnd1=Browser("Prod-CST1").GetROProperty("hwnd")
hwnd2=Browser("Prod-CST1").Object.HWND
Set cWindow=Window("hwnd:="&hwnd2)
cWindow.Minimize

and this code is for Restoring window
hwnd3=Browser("Advertiser: Ongoing").GetROProperty("hwnd")
hwnd4=Browser("Advertiser: Ongoing").Object.HWND
Set cWindow=Window("hwnd:="&hwnd4)
cWindow.Restore


another example to use HWND in QTP by using "InternetExplorer.Application"

 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
  Wait(1)
  WaitCount=WaitCount+1
 Loop

 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

No comments:

Post a Comment