Best way to find the window name from within a ButtonControl function?

I apologize if this is in the manual, but I can't seem to find it...

From within a ButtonControl function, I would like to determine the window name of the window containing the button that was pressed. What is the best way to do this?

Maybe this:
windowName=WinName(0,1)
?

Or this:
windowName=WinList("*","","WIN:")
?

A related question: If a ButtonControl function is executing, is the target window guaranteed to be the window containing the button that was pressed?

Thanks in advance for any help you can lend.

Adam

I suggest you convert your action procedure to the "new-style" action procedure that takes a structure as a parameter. You can then use the win member of the WMButtonAction structure parameter passed to your action procedure. For more information look at the command help entry for "Button" and also execute the following command on Igor's command line:
DisplayHelpTopic "Using Structures with Windows and Controls"
adamltaylor wrote:
A related question: If a ButtonControl function is executing, is the target window guaranteed to be the window containing the button that was pressed?

Almost guaranteed :)

In order to click a button, the window has to be the active window, so in most cases it will be. But other things can intrude, like window hook functions. Your own code might change the active window at some point. It's surprisingly easy to do accidentally if you call into other functions, and it is guaranteed if you create a new window in response to your button click.

In general, I don't count on the active window being the one containing the button. I almost always use the /W flag or win= keyword as appropriate in order to make sure Nothing Can Go Wrong. And I do what Adam says- I use the modern structure-based action procedures and I use the win member of the structure (present in all control action procedure structures) to get the name of the window.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com