Get full window title from partial window title

Started by cssyphus, November 27, 2024, 08:21:30 AM

Previous topic - Next topic

cssyphus

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.

td

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

"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

td

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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

cssyphus

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...?

td

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.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

cssyphus

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.

kdmoyers

The mind is everything; What you think, you become.

cssyphus

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 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?