Home > Language Reference > Windows Management Functions > CloseWindow

CloseWindow

The CloseWindow function closes the specified window.

Usage

Used to close an application or a dialog box. Prefer to use KillApp function if you do not want to save the current document when you exit the application.

Syntax

ret=CloseWindow(<window_name> [,forced|immediate])

Parameters

<window_name>, string, window name of the window to close. You can truncate <window_name> to close a window whose title starts with the specified characters.

forced|immediate, optional keyword. If forced is used (default value), the window is forced to close after 30 seconds (the user can save an unsaved document during this time). If Immediate is used, the window is closed immediately.

Return value

ret, optional numeric return value. If the window has been successfully closed 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

CloseWindowRegEx
KillApp

Examples

'Launch notepad
Shell("notepad")
'Wait until the notepad window is displayed
UseWindow("NOTEPAD.EXE|Edit|Untitled")
'Close main notepad window
CloseWindow("NOTEPAD.EXE|Notepad|Untitled")


'Launch notepad
Shell("notepad")
'Wait until the notepad window is displayed
UseWindow("NOTEPAD.EXE|Edit|Untitled")
'Type some text
SendKeys("Hello")
'Force the close of notepad window after 30 secs, no save is done. The 1 parameter is the instance number of notepad window.
CloseWindow("NOTEPAD.EXE|Notepad|Untitled",1,forced)