UseWindowHandle
Windows management function.
The UseWindowHandle function specifies the window (through the window handle) to which subsequent keyboard, mouse and menu actions are directed.
Syntax
UseWindowHandle(<handle>)
or
ret=UseWindowHandle(<handle>)Parameters
<handle>, numeric. Handle of the window to which subsequent keyboard, mouse and menu actions are directed.
WinTask will try to find the window defined by UseWindowHandle for a period of time defined by the system variable #ActionTimeout. Once the window is found, WinTask makes it active and sends all actions to it. This function works as UseWindow but allows to send actions to a window where the EXE part of the window name changes from one execution to an other (for instance, when installing Acrobat Reader several times).
Return value
Ret, numeric return code. When the window with its <handle> has been found and can be activated, the function returns 0, otherwise use this return code for Error Handling.
See also
Examples
#Ignoreerrors=1
#ActionTimeout=12
a=GetWindowhandle("WORDPAD.EXE|RichEdit20A|doc - WordPad|1")
ret=UseWindowhandle(a)
msgbox(ret)
An error code is displayed as WordPad window is not there.
shell("wordpad.exe")
a=GetWindowhandle("WORDPAD.EXE|RichEdit20A|document - WordPad|1")
UseWindowhandle(a)
WordPad window takes focus and is ready to receive actions.Example code
The script below installs Acrobat ; two functions are defined for testing if the button we want to click is ready for being clicked ; GetWindowHandle and UseWindowHandle are used (instead of UseWindow) as window names varies from one installation to another.
'Function waits for object objet$ to have focus for Tmax seconds
function wait_focus(objet$,Tmax)
local i, exitr, a$
i=0
exitr=0
repeat
a$=focus$()
if instr(a$,objet$)=0 then
pause 1
i=i+1
if i > Tmax then
msgbox("wait too long for "+objet$)
stop
endif
else
exitr=1
endif
until exitr=1
endfunction
'--------------------------------------------
'Function waits for object objet$ to be on top for Tmax seconds
function wait_top(objet$,Tmax)
local i, exitr, a$
i=0
exitr=0
repeat
a$=top$()
if instr(a$,objet$)=0 then
pause 1
i=i+1
if i > Tmax then
msgbox("wait too long for "+objet$)
stop
endif
else
exitr=1
endif
until exitr=1
endfunction
'-----------------------------------------------
#ActionTimeout=10
'Start Acrobat setup from CDROM
Shell("f:\Acrobat4\Setup.exe",1)
'License window
wait_focus("License",10)
a=getwindowhandle(top$())
usewindowhandle(a)
Click(Button,"&Accept")
'Installation choice
wait_focus("Button|Typical",10)
a=getwindowhandle(top$())
usewindowhandle(a)
Click(Button,"&Next >")
'User information window
wait_top("User information",10)
a=getwindowhandle(top$())
usewindowhandle(a)
Click(Button,"&Next >")
'Confirmation window
wait_focus("Button|&Yes",10)
a=getwindowhandle(top$())
usewindowhandle(a)
Click(Button,"&Yes")
'Last validation
wait_focus("Button|&Next",10)
a=getwindowhandle(top$())
usewindowhandle(a)
Click(Button,"&Next >")