Find child window (get handle); compare properties

Syntax1 - specified child window

int child(text [class] [window] [flags] [propCSV] [matchindex|array])
int childtest(hwnd text [class] [window] [flags] [propCSV])

 

Before QM 2.3.4 used this instead.

Instead of propCSV used two parameters x y and several additional flags.

 

int child(text [class] [window] [flags] [x y] [matchindex|array])
int childtest(hwnd text [class] [window] [flags] [x y])

 

Control id can be specified before text:

int child(id [text] [class] [window] [flags] [x y] [matchindex|array])
int childtest(hwnd id [text] [class] [window] [flags] [x y])

 

x y - used for multiple purposes, depending on flags. Default: the child window must contain this point in window.

 

These flags can be used to change x y meaning:

8 x and y are coordinates in window client area.
32 x and y are screen coordinates.
8|32 x and y are coordinates in the work area.
128 x is style.
0x100 y is extended style.
0x8000 x and y used to specify a callback function and a value to pass to it.

 

 

Syntax2 - child window from point

int child(x y [window] [flags2])
int childtest(hwnd x y [window] [flags2])

 

Syntax3 - child window from mouse position

int child(mouse) [flags2]
int childtest(hwnd mouse) [flags2]

 

Syntax4 - child window from accessible object

int child(acc)
int childtest(hwnd acc)

 

Syntax5 - the focused child window

int child

 

Parameters

text - child window text.

class - child window class name.

window - parent window.

flags:

1

text is full or with wildcard characters (*?).

  • String "*" matches child windows with no name.
2 text case insensitive.
4 Get text using an alternative method. Use for Edit and some other controls if gets wrong text.
16 Must be direct child. If not set, the function also finds children of direct children and so on.
0x200 text is regular expression.
0x400 Must be visible.

propCSV - list of other properties in format "name1=value1[]name2=value2[]...". It is CSV string with separator =. Default: "".

name value
id Control id.
accName Accessible object Name property. Must be full or with wildcard characters; case insensitive. Useful with controls that take accessible name from a sibling Static control.
wfName

Windows Forms (.NET) control name. Must be full or with wildcard characters; case insensitive.

Use with controls where class name looks like "WindowsForms10.xxx.xxx". Don't use id, it is not constant. You can see wfName in QM status bar. Also can record.

xy

x and y coordinates of a point in window that must be in the child window too. Relative to the client area of the window. Examples:

"xy=100 50"
"xy=0.9 0.1" ;;near top-right
callback

Address of a callback function, optionally followed by a value to pass to it. Example:

F"callback={&Function} {aValue}"

  Also supports style, exStyle, cClass, cText, cId, cFlags, GetProp. Same as with win.

matchindex (QM 2.2.0) - 1-based index of matched child window in the parent window. Use when there are several child windows (in the parent window) that match other properties (text, class, etc).

array (QM 2.2.1) - variable of type ARRAY(int) that will receive handles of all matching child windows.

 

x, y - a point in the parent window or screen (if window is 0 or used flag 32).

flags2 (syntax 2 and 3):

1 QM 2.3.4. If there is no child window, get the top-level window.
8 x and y are coordinates in client area of window.
16 Must be direct child.
32 x and y are screen coordinates.
8|32 x and y are coordinates in the work area.

mouse (syntax 3) - literal mouse.

accobj (syntax 4) - accessible object (an Acc or IAccessible variable).

hwnd (childtest) - handle of child window to test.

 

Remarks

Finds a child window (control) in the specified window, and returns its handle. Returns 0 if not found. Error if parent window does not exist.

 

Syntax1: Finds child window whose text and other properties match the specified.

 

Syntax2: Gets handle of child window from the specified point in its parent window. If window is omitted or "" - active window. If window is literal 0, parent can be any window (x and y are screen coordinates).

 

Syntax3: Gets handle of child window (except invisible) from mouse pointer position.

 

Syntax4: Gets handle of child or top-level window that matches or contains accessible object accobj.

 

Syntax5: Gets handle of child window that has focus. To get focused window of current thread, use GetFocus instead.

 

Function childtest compares child window (hwnd) properties with the specified, and returns 1 if they match, or 0 if not. If window is omitted or literal 0, does not compare it. See also WinTest.

 

See also: id acc htm

 

Examples

act child("Hex" "Button" "Calculator")
if child("The text*" "Static" "Notepad" 1)
	bee
int h = child(100 100 "Notepad")
h = child(mouse)
if(childtest(h "OK" "Button")) but h