Attempting to use WinGet with multiple criteria for WinTitle

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bschamel
Posts: 15
Joined: 08 Aug 2016, 11:18

Attempting to use WinGet with multiple criteria for WinTitle

18 Sep 2018, 10:39

I have code that operates differently based on the window handle it's passed, though in certain cases, I want it to behave as though handle passed in was something else (in this case, when the passed window is TextPad's 'Find' dialog box, I want it to use the main TextPad window instead.

Here's the code:

Code: Select all

WinGetTitle, winTitle, ahk_pid %winPID%
	
	IfEqual winTitle, Find 
	{
		WinGet exeName, ProcessName, ahk_pid %winPID%
		IfInString exeName, TextPad
		{ 
			Debug("Before changing folder " winTitle ", " winPID)
			OldMatchMode := A_TitleMatchMode
			SetTitleMatchMode 2
			WinGet winPID, pid, TextPad - ahk_exe Textpad.exe
			WinGetTitle winTitle, ahk_pid %winPID%
			SetTitleMatchMode %OldMatchMode%
		}
	}
	
	Debug("Finding related to window " winTitle ", " winPID)
Here's the output info I get:

Code: Select all

VMandHost.ahk: Before changing title: Find, 8636
VMandHost.ahk: Finding related to window Find, 8636
Some background info if you're not familiar with TextPad:

The window I'm trying to replace is always named either 'Find' or 'Find in Files'
The title of the main window is always of the format 'TextPad - <PATH_TO_FILE_CURRENTLY_OPEN>'

It's my understanding that the second WinGet and WinGetTitle should be retrieving info for the main window, but it's clearly not. What am I doing wrong?
lexikos
Posts: 9592
Joined: 30 Sep 2013, 04:07
Contact:

Re: Attempting to use WinGet with multiple criteria for WinTitle

19 Sep 2018, 05:38

The second WinGet PID is retrieving the PID of the main window, which is of course the same as the PID of the Find window. They belong to the same process.

The second WinGetTitle gets the title of the Find window because you did not specify any criteria other than the PID, and the Find window is the top-most window of that process.

Use ahk_id and the window's HWND (WinGet ID or WinExist) to uniquely identify the window.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ArkuS, Chunjee, Frogrammer and 369 guests