int win(name [class] [exename] [flags] [x y] [matchindex|array]) int wintest(hwnd name [class] [exename] [flags] [x y])
int win(x y [workarea]) int wintest(x y [workarea])
int win(mouse) int wintest(hwnd mouse)
int win
name - window title. By default, name can be partial and must match case. Empty string ("") matches any name.
class - window class name. Must be full, case insensitive. Default: "" (any).
exename - program. Filename (e.g., "NOTEPAD") or full path (e.g., "$system$\notepad.exe"). Also can be process id (QM 2.2.0). Default: "" (any).
flags - combination of values listed below. Default: 0.
| 1 | name must match exactly or may contain wildcard characters (*?). For example, to tell that window name must end with " - Notepad", use "* - Notepad" and flag 1. To tell that window name must be exactly "Notepad", use "Notepad" and flag 1. String "*" matches windows with no name. This flag cannot be used with flag 0x200 (regular expression). |
| 2 | name is case insensitive. |
| 4 | Window must not be popup. |
| 8 | Window must be popup. |
| 16 | name is list of names. |
| 32 | exename is name or +classname of owner window. Also can be handle (QM 2.2.0). |
| 64 | x is handle of owner window. Cannot be used with 32, 128 and 0x8000. |
| 128 | x is style. Cannot be used with 64 and 0x8000. |
| 0x100 | y is extended style. Cannot be used with 0x8000. |
| 0x200 | name is regular expression. Alternatively, use $ character at the beginnig. For example, win("$^A.*Notepad$") finds window whose name begins with "A" and ends with "Notepad". |
| 0x400 | Must be visible. It is default option if class is not specified and opt hidden 1 not used. It isn't default option for wintest (QM 2.2.0). |
| 0x800 | Use wildcard characters in class. |
| 0x1000 | If window still does not exist or is invisible, wait max 0.5 s. |
| 0x8000 | Use callback function. |
x, y - some point in screen that belongs to the window.
matchindex (QM 2.2.0) - 1-based index of matched window. Use when there are several windows that match other properties (name, class, etc).
array (QM 2.2.1) - variable of type ARRAY(int) that will receive handles of all matching windows.
workarea - if nonzero, coordinates are relative to the work area. The work area is the portion of the screen not obscured by the system taskbar or by application desktop toolbars.
hwnd - handle of window to test.
mouse - literal mouse.
win returns top-level window handle. If window not found, returns 0.
wintest evaluates window (hwnd) properties, and returns 1 if they match, or 0 if not. If window list is used (flag 16), it returns 1-based index in the list.
win can be used in macro commands, where window is required.
wintest is useful in filter functions.
You can see window class, name and exename in the QM status bar.
int h = win ;;active window h = win("Notepad") ;;name "Notepad" h = win("Find" "#32770" "NOTEPAD" 1|0x400) ;;name "Find", class "#32770", program "notepad", name must match exactly, must be visible h = win("" "Notepad" "" 0 100 100) ;;class "Notepad", must be at 100x100 pixels in screen h = win(200 0.5) ;;window that is at 200 pixels horizontally and half of screen height vertically act win(mouse) ;;activate window that is at the mouse pointer position int h=win sel wintest(h "Visual[]Quick" "" "" 16) case 1 out "Visual" case 2 out "Quick" case 0 out "other" out ARRAY(int) a; int i; str sc sn out "[][9]ALL VISIBLE WINDOWS" win("" "" "" 0 0 0 a) for(i 0 a.len) sc.getwinclass(a[i]) sn.getwintext(a[i]) out "%i '%s' '%s'" a[i] sc sn out "[][9]ALL INVISIBLE WINDOWS" opt hidden 1 win("" "" "" 0 0 0 a) for(i 0 a.len) if(!hid(a[i])) continue ;;this window is visible sc.getwinclass(a[i]) sn.getwintext(a[i]) out "%i '%s' '%s'" a[i] sc sn out "[][9]ALL WINDOWS OF EXPLORER" opt hidden 1 win("" "" "explorer" 0 0 0 a) for(i 0 a.len) sc.getwinclass(a[i]) sn.getwintext(a[i]) out "%i '%s' '%s'" a[i] sc sn