get window NAME for a particular window ID

Started by fhammer, December 18, 2016, 06:35:47 PM

Previous topic - Next topic

fhammer

Is there a simple way to get the name of the window for a particular window ID? I tried using WinItemizeEx, until I noticed that it is one of the few functions which won't accept a window ID for the partial-window-name parameter. Thanks.

fhammer

#DEFINEFUNCTION WinID2WinName(id)
; returns the name of the window with a particular id

  list = WinItemNameID()
  loc = ItemLocate(id,list,"|")
  name = ItemExtract(loc-1,list,"|")

  Return name

#ENDFUNCTION

Could be combined into a single statement.

snowsnowsnow

fhammer: Nice.  Quite natty, in fact.

For the OP: This works by finding the WindowID in the list returned by WinItemNameID(), then returning the item in that list that precedes the found WindowID.  Note that this could fail in a perverse case where some window had the same name as the WindowID.

Here's another way that uses functions in the Control Manager extender:

name = cWndInfo(cWinIdConvert(WinId),0)

FWIW, I use cWndInfo() a lot in my code.

td

Or

Code (winbatch) Select

hWnd = DllHwnd(WinId)
if hWnd  then strTitle = cWndInfo(hWnd, 0)
else strTitle = ''
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade