How to get window's name

I am writing a function that finds all graphs in an experiments, saves each one to PDF, and then closes (kills) the graphs. I have two questions related to windows.

1. Is there a way to obtain the name of the topwindow? I have a set of graphs with assigned names and I’d like to save each one using the window’s name as the filename. I have used

getWindow kwTopWin, wtitle

to get the window’s title, but in some cases this is not the same as the window's name and I need the name. Is there a command like

getWindow kwTopWin, wname

?

2. Is there a way to check whether the top window is a graph?
Thanks in advance.

Pietro
I'd go for the WinList command. It returns the names of the windows from front to back.

In order to test whether the topmost window is a graph, you could compare the the first item in the result lists corresponding to all windows and solely to graph windows
print winlist("*",";","")

vs
print winlist("*",";","win:1")


HJ