Show / Hide Table of Contents

Method wnd.runAndFind


Overload

Opens and finds new window. Ignores old windows. Activates.

public static wnd runAndFind(Action run, Seconds timeout, string name = null, string cn = null, WOwner of = default, WFlags flags = 0, Func<wnd, bool> also = null, WContains contains = default, bool activate = true)
Parameters
run  (Action)

Callback function. Should open the window. See example.

timeout  (Seconds)

How long to wait for the window. Seconds. Can be 0 (infinite), >0 (exception on timeout) or <0 (no exception). More info: Wait timeout.

name  (string)

Window name. Usually it is the title bar text. String format: wildcard expression. null means "can be any". "" means "no name".

cn  (string)

Window class name. String format: wildcard expression. null means "can be any". Cannot be "".

of  (WOwner)

Owner window, program or thread. Depends on argument type:

  • wnd - owner window. Will use wnd.IsOwnedBy with level 2.
  • string - program file name, like "notepad.exe". String format: wildcard expression. Cannot be "" or path.
  • WOwner - WOwner.Process(process id), WOwner.Thread(thread id).

See wnd.getwnd.Owner, wnd.ProcessId, process.thisProcessId, wnd.ThreadId, process.thisThreadId.

flags  (WFlags)
also  (Func<wnd, bool>)

Callback function. Called for each matching window. It can evaluate more properties of the window and return true when they match. Example: also: t => !t.IsPopupWindow. Called after evaluating all other parameters except contains.

contains  (WContains)

Defines an object that must be in the client area of the window:

  • UI element: elmFinder or string like "name" or "e 'role' name" or "e 'role'".
  • Child control: wndChildFinder or string like "c 'cn' name" or "c '' name" or "c 'cn'".
  • Image(s) or color(s): uiimageFinder or string "image:..." (uses a uiimageFinder with flag IFFlags.WindowDC).
  • OCR text: ocrFinder or string "ocr:..." (uses an ocrFinder with flag OcrFlags.WindowDC).
activate  (bool)

Activate the window. Default: true.

Returns
wnd

Window handle as wnd. On timeout returns default(wnd) if timeout < 0 (else exception).

Exceptions
TimeoutException

timeout time has expired (if > 0).

AuWndException

Failed to activate.

ArgumentException
  • cn is "". To match any, use null.
  • of is "" or 0 or contains character '\\' or '/'. To match any, use null.
  • Invalid wildcard expression ("**options " or regular expression).

Remarks

This function isn't the same as just two statements run.it and wnd.find. It never returns a window that already existed before calling it.

Examples

var w = wnd.runAndFind(
	() => run.it(folders.Windows + @"explorer.exe"),
	10, cn: "CabinetWClass");
print.it(w);