Advanced programming - WMWinHookStruc

Hello to the community,
I´m quite new to Igor and I´m dealing with a code which was written by someone else and it has been built in this way:
there is a main panel from which you can operate onto a data set. Among the other things it is possible to plot some listed wave into different windows.
Now I have to implement some features in this panel and I need to store the name of the window (i.e. "PanelWindow", "Graph0", "Graph5") into a global string.
That global string will be then addressed and read by other routines to know in which window operations have to be performed.

In a routine already present, I´ve found that an interesting Igor feature is used: the WMWinHookStruct.
Whenever the left button of the mouse is pressed to make a window active, the main panel is updated.
Code is listed below:

function Reactivate(winStruct)
struct WMWinHookStruct &winStruct

switch (winStruct.eventCode)
case 0: // reactivate window
PrepareGlobals() // in case someone deleted something

UpdateMainPanel()
break
endswitch
return 0
End

Anytime a panel is selected and the active graph is changed, this routine updates data shown on the main panel.

To test this possibility to implement my features I´ve added some lines to the code in order to print the name of the selected window; I´ve tried both with:
WinName(0,1,1) to plot the name of graph windows
WinName(0,1,64) to plot the name of Panel windows
with several combinations of winList
and with the lines:
GetWindow kwTopWin, title
print S_Value

but I haven´t been able to reach the goal. Anyway I´ve found a strange behaviour: whenever I press the MainPanel window the script is run and the name of the panel window and/or the name of the topmost graph are printed. But If I select any graph window, the code lines aren´t run and no names are printed.

Any suggestion?

Thanks in advance for your help
marco
Welcome to the forum.
Please use <pre><code class="language-igor">...</code></pre> tags to post code, it's easier to read for us and thus easier to help you.

The 'strange behavior' is probably correct. I assume the winhookfunction is installed for the main panel but it is not for the other windows. Check for setwindow in the code and in the help file.

I am not entirely sure about your main task (actually, what is 'the' in the window (i.e. "PanelWindow"..." referring to).
Do you want to know the names of windows that have been activated since a certain task has been executed the last time? This would indeed be implements by a hookfunction and setwindow.
If you just want to apply some settings to windows that were programmatically created, you might be better off to give unique names yourself and pass these to a routine.

HJ