How to Distinguish between Two Windows with the Same Name
Keywords: winidget
Question:
I need to distinguish between two windows with the same name "Registry Editor". I run the registry editor and I get the window with the "Registry Editor" name, then when I am done searching the registry a window comes up with the name "Registry Editor" and a OK button.Answer:
Each individual window has a Window Title and a Window ID. The Window Name is determined by the application and there can be more that one window with the same name. The Window ID is determined by the Operating System and is always unique. Therefore the Window Id can change upon each instance the process is run.
There are a couple of solutions to your problem.
The easiest is to change the main parent windows title to something unique, (like "-Registry Editor-") using the function WinTitle, so that when the next window comes up with the name "Registry Editor" and a OK button, you can decifer the windows.WinTitle("Registry Editor","-Registry Editor-")
Another alternative is to store of the main registry editors window id, as soon as the window is launched. Then you can monitor the window ID of the currently active window with the title "Registry Editor". If the ID is different from the main window ID, then you can assume you have your window with the name "Registry Editor" and a OK button.mainid = WinIDGet("Registry Editor") ;Wait until a different window with the name "Registry Editor" appears While @True id = WinIDGet("Registry Editor") if id != mainid then break Endwhile Message("Window Locator","New window with the same name appeared!")
Finally, you have the option of using the Control Manager Extender functions, to monitor for your window to appear with an OK button, by looking specifically for that OK button. See the function cWndInfo and cWndExist.
Note:
- Any WIL function that accepts a window-name or partial window name as a paramter can also accept a window ID.
- When using titles, Winbatch will *always* go after the most recently used window.
Article ID: W13363Filename: Distinguish between Two Windows with Same Name.txt