Function Reference


WinActivate

Activates (gives focus to) a window.

WinActivate ( "title" [, "text"] )

Parameters

title The title/hWnd/class of the window to activate. See Title special definition.
text [optional] The text of the window to activate. Default is an empty string. See Text special definition.

Return Value

Success: the handle of the window.
Failure: 0 if window is not found or cannot be activated.

Remarks

You can use the WinActive() function to check if WinActivate() succeeded. If multiple windows match the criteria, the window that was most recently active is the one activated. WinActivate() works on minimized windows. However, a window that is "Always On Top" could still cover up a window you Activated.

After a successful activation @extended is set to 1 if the the window was already active, 2 if not.

Related

WinClose, WinKill, WinMove, WinSetState, WinTitleMatchMode (Option)

Example

#include <MsgBoxConstants.au3>

Example()

Func Example()
        ; Run Notepad
        Run("notepad.exe")

        ; Test if the window is activated and display the results.
        If WinActivate("[CLASS:Notepad]", "") Then
                MsgBox($MB_SYSTEMMODAL + $MB_ICONWARNING, "Warning", "Window activated" & @CRLF & @CRLF & "May be your system is pretty fast.")
        Else
                ; Notepad will be displayed as MsgBox introduce a delay and allow it.
                MsgBox($MB_SYSTEMMODAL, "", "Window not activated" & @CRLF & @CRLF & "But notepad in background due to MsgBox.", 5)
        EndIf

        ; re Test if the window is now activated and display the results.
        If WinActivate("[CLASS:Notepad]", "") Then
                MsgBox($MB_SYSTEMMODAL, "", "Window NOW activated")
        Else
                MsgBox($MB_SYSTEMMODAL + $MB_ICONERROR, "Error", "Window not activated")
        EndIf

        ; Close the Notepad window using the handle returned by WinWait.
        WinClose("[CLASS:Notepad]", "")
EndFunc   ;==>Example