WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: fhammer on December 18, 2016, 06:35:47 PM

Title: get window NAME for a particular window ID
Post by: fhammer on December 18, 2016, 06:35:47 PM
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.
Title: Re: get window NAME for a particular window ID
Post by: fhammer on December 18, 2016, 08:11:36 PM
#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.
Title: Re: get window NAME for a particular window ID
Post by: snowsnowsnow on December 19, 2016, 07:59:25 AM
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.
Title: Re: get window NAME for a particular window ID
Post by: td on December 19, 2016, 08:16:13 AM
Or

Code (winbatch) Select

hWnd = DllHwnd(WinId)
if hWnd  then strTitle = cWndInfo(hWnd, 0)
else strTitle = ''