WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: cssyphus on November 27, 2024, 08:21:30 AM

Title: Get full window title from partial window title
Post by: cssyphus on November 27, 2024, 08:21:30 AM
What is the best way to get the full title of an existing window, from a partial window name?

For example, if VLC is playing, how to get the full title of that window?

Currently, I winActivate() the window using a partial window name and then use winGetActive() to get the full name. BUT... I do not wish to winActivate() the window and give it focus.

Is there a better way to do this? My brain is telling me I should know this... but cannot think of it at the moment.
Title: Re: Get full window title from partial window title
Post by: td on November 27, 2024, 08:54:56 AM
After obtaining the window's handle, you could use the Control Manager extender's cWndInfo function.

;; Thanks MSFT's "new and improved" OS this may
;; take a few seconds to display the result.
strPartName = '~Notepad'
Run("notepad.exe", '')

AddExtender('wwctl44i.dll',0,'wwctl64i.dll')
WinId = WinIdGet(strPartName)
hWnd = DllHwnd(WinId)

if hWnd  then strTitle = cWndInfo(hWnd, 0)
else strTitle = ''
Message("Notepad Title", strTitle)
exit

Title: Re: Get full window title from partial window title
Post by: td on November 27, 2024, 09:11:06 AM
This works with one less function call.

;; Thanks MSFT's "new and improved OS" this may
;; take a few seconds to display the result.
strPartName = '~Notepad'
Run("notepad.exe", '')

AddExtender('wwctl44i.dll',0,'wwctl64i.dll')
hWnd = DllHwnd(strPartName)

if hWnd  then strTitle = cWndInfo(hWnd, 0)
else strTitle = ''
Message("Notepad Title", strTitle)
exit
Title: Re: Get full window title from partial window title
Post by: cssyphus on November 27, 2024, 09:15:19 AM
Thanks for that Tony... I had forgotten about the CtrlMgr extension.

And thanks, too, for the heads up on timing... unfortunately, the "few seconds" would be a show-stopper in this case. I will figure out a work-around.

I thought there would be a more direct way to do this. Feature request? A new function like GetFullWinTitle("~partial window name") might be useful...?
Title: Re: Get full window title from partial window title
Post by: td on November 27, 2024, 05:22:39 PM
The timing issue is because of the particular executable. Notepad has a few quirky characteristics because it is written by MSFT and because it is a "managed" application.
Title: Re: Get full window title from partial window title
Post by: cssyphus on November 28, 2024, 11:18:50 AM
Ahhhh - that's helpful to know. I was ass/u/meing (Walter Matthau) that the control manager extender now had these limitations under Win10+, but you say it all depends on the app.exe being queried. I get it. So, in most cases (and probably my own use case) this could be a near-instant solution. Tweaking time! Many, many, many thanks as ever Mr T.
Title: Re: Get full window title from partial window title
Post by: kdmoyers on November 29, 2024, 06:33:37 AM
I think you mean Tony Randall  https://www.youtube.com/watch?v=KEP1acj29-Y
Title: Re: Get full window title from partial window title
Post by: cssyphus on December 02, 2024, 01:39:32 PM
No, I actually meant Walter Matthau... but I had the wrong movie. Matthau was the coach in the iconic 1976 Bad News Bears, but this scene (https://www.youtube.com/watch?v=LUv3PXLO0hM&t=148s) was in the lousy sequel "Bad News Bears in Breaking Training". Didn't see the movie, but was unfortunate enough to see the trailer (which included this clip) at some point in a long and misspent life.

Ironically, Walter Matthau played the other main character in the movie version of the clip you posted (from the Odd Couple TV series...) and even odder, I had just watched the 1968 version of that movie, starring Walter Matthau, the night before you posted that reply. What are the odds?