Retrieves the internal handle of a window.
WinGetHandle ( "title" [, "text"] )
title | The title/hWnd/class of the window to get the handle. See Title special definition. |
text | [optional] The text of the window to get the handle. Default is an empty string. See Text special definition. |
Success: | a handle to the window. |
Failure: | sets the @error flag to non-zero if the window is not found. |
This function allows you to use handles to specify windows rather than "title" and "text".
Once you have obtained the handle you can access the required window even if its title changes.
GUICreate, WinList, WinSetTitle
#include <MsgBoxConstants.au3>
Example()
Func Example()
; Run Notepad
Run("notepad.exe")
; Wait 10 seconds for the Notepad window to appear.
WinWait("[CLASS:Notepad]", "", 10)
; Retrieve the handle of the Notepad window using the classname of Notepad.
Local $hWnd = WinGetHandle("[CLASS:Notepad]")
If @error Then
MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle of Notepad.")
Exit
EndIf
; Display the handle of the Notepad window.
MsgBox($MB_SYSTEMMODAL, "", $hWnd)
; Close the Notepad window using the handle returned by WinGetHandle.
WinClose($hWnd)
EndFunc ;==>Example