Show / Hide Table of Contents

Method wnd.find(+ 1 overload)


Overload

Finds a top-level window and returns its handle as wnd.

public static wnd find(string name = null, string cn = null, WOwner of = default, WFlags flags = 0, Func<wnd, bool> also = null, WContains contains = default)
Parameters
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).
Returns
wnd

Window handle, or default(wnd) if not found. See also: wnd.Is0.

Exceptions
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

To create code for this function, use tool Find window.

If there are multiple matching windows, gets the first in the Z order matching window, preferring visible windows.

On Windows 8 and later may skip Windows Store app Metro-style windows (on Windows 10 few such windows exist). It happens if this program does not have disableWindowFilteringtrue in its manifest and is not uiAccess; to find such windows you can use wnd.findFast.

To find message-only windows use wnd.findFast instead.

Examples

Try to find Notepad window. Return if not found.

wnd w = wnd.find("* Notepad");
if(w.Is0) { print.it("not found"); return; }

Try to find Notepad window. Throw NotFoundException if not found.

wnd w1 = wnd.find(0, "* Notepad");

Wait for Notepad window max 3 seconds. Throw NotFoundException if not found during that time.

wnd w1 = wnd.find(3, "* Notepad");

Wait for Notepad window max 3 seconds. Return if not found during that time.

wnd w1 = wnd.find(-3, "* Notepad");
if(w.Is0) { print.it("not found"); return; }

Wait for Notepad window max 3 seconds. Throw NotFoundException if not found during that time. When found, wait max 1 s until becomes active, then activate.

wnd w1 = wnd.find(3, "* Notepad").Activate(1);

Overload(top)

Finds a top-level window and returns its handle as wnd. Can wait and throw NotFoundException.

public static wnd find(Seconds wait, string name = null, string cn = null, WOwner of = default, WFlags flags = 0, Func<wnd, bool> also = null, WContains contains = default)
Parameters
wait  (Seconds)

The wait timeout, seconds. If 0, does not wait. If negative, does not throw exception when not found.

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).
Returns
wnd

Window handle. If not found, throws exception or returns default(wnd) (if wait negative).

Exceptions
NotFoundException
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).