CloseWindowRegEx

Windows management function.

The CloseWindowRegEx function closes the specified window, using Regular Expressions to specify the window title part of the window name. Not available in WinTask Lite.

Usage

Used usually to close a child window within a parent one, when the window name of the child window changes from one execution to another.

Syntax

CloseWindowRegEx(<window_name> [[,<instance>], forced])
or
ret=CloseWindowRegEx(<window_name> [[,<instance>], forced])

Parameters

<window_name>, string. window name (see this topic) of the window to close. You can use the SPY tool to manually determine the caption of a window. During Recording mode they will be inserted automatically. The Regular expressions can be used to specify the title part of the window name, for example if in "NOTEPAD.EXE|Edit|20.txt - Notepad" 20 is a day number which changes every day, CloseWindowRegEx("NOTEPAD.EXE|Edit|[0-9][0-9].* - Notepad") triggers on a window title whatever day number in it.

<instance>, optional parameter, instance number of the window.

forced : optional keyword. If specified, the window is closed after 30 seconds even if a dialog box prompts for an answer.

WinTask will try to close the window defined by CloseWindowRegEx for a period of time defined by the system variable #ActionTimeout.

Return value

Ret, numeric return code. When the <window_name> has been found and can be closed, the function returns 0, otherwise use this return code for Error Handling.

Remarks

We describe below the most common cases for Regular Expressions:

Character

Description

Examples

.

Matches a single character

a.r matches a0r, air, a£r,...

*

Repeats the previous character zero or several times

abc* matches ab, abc, abcc, abccc, ...

+

Repeats the previous character one or several times

abc+ matches abc, abcc, abccc, ...

?

Makes the preceding character optional

abc? matches ab or abc

|

Alternation, regular expression equivalent of OR

200[6|7] matches 2006 or 2007

[]

Matches one out of several characters

gr[ae]y matches gray, grey but not graey

{n}

Repeats n times the previous character

a{3} matches aaa

{n,m}

Repeats the previous character between n and m times

a{2,4} matches aa, aaa, aaaa

[ - ]

Matches one out of a range of several characters

gr[0-9]y matches gr0y, gr1y, ... gr9y but not gr19y

[ ^ - ]

Excludes the range of several characters

gr[^0-9]y matches gray, grby, grcy, ... grzy but not gr0y, gr1y,... gr9y

 ^

Outside a [, matches at the start of the string

^begin matches begin, beginning, begin with

$

Matches at the end of the string

end$ matches end, will end, at the end

\charact.

A backslash escapes special characters above their meaning

\+ matches + (and so the + sign does not have its special meaning)

See also

UseWindowRegEx

Examples

We list below the most common cases

Single character
Closes the notepad window whatever character is after Doc

CloseWindowRegEx("NOTEPAD.EXE|Notepad|Doc. - Notepad|1")

Triggers for any window Doca, Docb, ..., Doc0, Doc1, ....

Single character in a list
Closes the notepad window if, after Doc, the year is 2005, 2006 or 2007

CloseWindowRegEx("NOTEPAD.EXE|Edit|Doc200[567] - Notepad|1")

Triggers for any window Doc2005, Doc2006, or Doc2007

Single character NOT in a list
Closes the notepad window if, after Doc, the year is NOT 2005, 2006 or 2007

CloseWindowRegEx("NOTEPAD.EXE|Edit|Doc200[^567] - Notepad|1")

Triggers for any window Doc2000, Doc2001, Doc2002, Doc2003, Doc2004, Doc2008, Doc2009 and Doc200a, Doc200b, ...

Single character within a range
Closes the notepad window if, after Doc, it can be any year in the 1990s

CloseWindowRegEx("NOTEPAD.EXE|Edit|Doc199[0-9] - Notepad|1")

Triggers for any window Doc1990, Doc1991,..., Doc1999