Home > FAQ > Useful Basic Tasks when writing a script > How do I find the window which has the focus?

Window Name

The window name parameter used in many Windows Management Functions is defined as :

<executable_module>|<window_class>|<window_title>[|<order_number] [,<instance_number>]


<executable_module>
, string, name of the executable file that starts the process to which the window belongs. For example:
    NOTEPAD.EXE

<window _class>, string, class of the window. A window class is a set of attributes that the system uses as a template to create a window. This part of the window name supports wildcard characters by truncating <window_class> string until maximum the first character. For example:
    Edit
    Afx:367539 which can be truncated in Afx: and maximum truncation allowed is A

<window_title>, string, title of the window. This part of the window name supports wildcard characters by truncating <window_tile> string. For example:
    Untitled - Notepad
    My document - Notepad
which can be truncated to an empty string for any notepad document

<order_number>, optional integer. It is needed when multiple controls within the parent window have the same class name and title.

<instance_number>, optional integer, index of the <executable_module> instance. If not specified, the first instance is used. An application can have several instances running simultaneously. The first (earliest launched instance) has instance 1, the second instance 2, etc.  

To generate a window name, use the SPY tool to manually or generate your script using Recording mode.

Window recognition at replay

If a window with the specified exact name is not found, WinTask attempts a fuzzy match. It tries to find a window with approximately the same window name by removing characters from the end of the title until eventually none is kept, and then the class (the first character is always kept). You can deactivate this mode with the system variable #UseExact. The switch to fuzzy-match mode is delayed: the delay is one-ninth of the value of #ActionTimeout, by default this is 3,33 sec (1/9 of 30 which is the default value of #ActionTimeout). However, if #ActionTimeout is less than or equal to 10, then only exact-match mode is used.

Examples

UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad", 1)
'NOTEPAD.EXE - executable module
'Edit - class speciying the window part where the text can be typed
'Untitled - Notepad title of the window as seen at the top of the window
'1 -  instance 1, only one notepad is opened


UseWindow("NOTEPAD.EXE|Edit",2)
'NOTEPAD.EXE - executable module
'Edit - class speciying the window part where the text can be typed
'No window title is provided, any window title triggers
'2 -  instance 2, two notepad are opened, the second instance will trigger

UseWindow("NOTEPAD.EXE|Edit|Mydoc", 1)
'NOTEPAD.EXE - executable module
'Edit - class speciying the window part where the text can be typed
'Mydoc - Any Notepad window title which title starts by Mydoc triggers
'1 -  instance 1, only one notepad is opened

UseWindow("NOTEPAD.EXE|Edit|U|1", 1)
'NOTEPAD.EXE - executable module
'Edit - class speciying the window part where the text can be typed
'U - Any Notepad window title which title starts by U triggers
'1 - control indexed 1 within Edit|U window
'1 -  instance 1, only one notepad is opened