Home > Language Reference > Windows Management Functions > UseWindowHandle

UseWindowHandle

The UseWindowHandle function specifies the handle of the window to bring to foreground.

Usage

For advanced users: the window handle (a numeric) is assigned when the window is created by the system, so this number changes from session to session. The handle can be acquired dynamically using GetFocusWindowHandle or GetTopWindowHandle functions.  

Syntax

ret=UseWindowHandle(<handle>)

Parameters

<handle>, integer, handle of the window to bring to foreground.

Return value

ret, optional numeric return value. If the window has been found within 30 seconds (this default value can be changed using #ActionTimeout), the function returns 0. If the function fails, the return value is a nonzero value (see Window Functions Error Codes).

See also

GetWindowHandle
GetFocusWindowHandle
GetTopWindowHandle

Example

'Return an error message after 12 secs
#ActionTimeout=12
a=GetWindowhandle("NOTEPAD.EXE|TTT|doc - notepad|1")
'As the specified window above does not exist, a contains 0 and UseWindowHandle returns an error
UseWindowHandle(a)

Shell("notepad")
a=GetWindowhandle("NOTEPAD.EXE|Notepad|doc - notepad|1")
msgbox(a)
ret=UseWindowHandle(a)
'The return code of UseWindowHandle is 0 as the a value is the handle of an existing window
msgbox(ret)