Best way to find the window name from within a ButtonControl function?
adamltaylor
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
DisplayHelpTopic "Using Structures with Windows and Controls"
July 3, 2012 at 07:51 am - Permalink
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
July 3, 2012 at 09:22 am - Permalink
Adam
July 3, 2012 at 10:24 am - Permalink