Move a cursor (in a subwindow) using a hook

Hi, I am trying to update a value in a SetVariable object whenever I move a cursor in a graph (similar to the Cursor Moved Hook Demo), except that this time the graph is a subwindow in a panel and I cannot find the way to make it work. Do you have any suggestions? Thank you.

Here is how I place a cursor in a subwindow

Cursor /W=Panel_Fit_Spectra_For_Energies#G0 A Spectrum_1D_Shifted pnt2x(w_Spectrum_1D_Shifted,0)

Good luck!

Note that graph subwindows don't have their own hook functions, you have a set a hook for the parent window to monitor for the cursor moved event. Maybe that is part of the problem?

Here's a modified Cursor Moved Hook example that hooks a subwindow

#pragma rtGlobals=3 // Use modern global access method.

Macro DemoSubWindowHook()
    Make/O/N=(10) xx=p*1000
    Make/O/N=(10) yy=sin(p/4)
    Make/O/T/N=(10) text="text for point "+num2istr(p)
    ExampleSubGraph()
End

Window ExampleSubGraph() : Graph
    PauseUpdate; Silent 1       // building window...
    Display /W=(69,49.25,699.75,444.5)/K=1  as "Graph with Subwindow"
    ShowInfo
    TextBox/C/N=readout/A=LT/X=1.66/Y=2.05 "\\JCMove the Cursor: the point number is shown here"
    ControlBar 40
    SetVariable xValue,pos={56.00,9.00},size={90.00,18.00},bodyWidth=80,title="X"
    SetVariable xValue,value=xx[0]
    SetVariable textValue,pos={174.00,9.00},size={144.00,18.00},bodyWidth=120
    SetVariable textValue,title="Text",limits={-inf,inf,0},value=text[0],noedit=1
    Display/W=(0.1,0.1,0.9,0.9)/HOST=#  yy vs xx
    ModifyGraph wbRGB=(65535,65534,49151),frameStyle=1, mode=4,marker=19
    Cursor/P A yy 0
    RenameWindow #,G0
    SetActiveSubwindow ##
    SetWindow kwTopWin,hook(myHook)=newCursorMovedHook
EndMacro

Function newCursorMovedHook(s)
    STRUCT WMWinHookStruct &s

    Variable statusCode= 0
   
    strswitch( s.eventName )
        case "cursormoved":
            // see "Members of WMWinHookStruct Used with cursormoved Code"
            NewUpdateControls(s.winName, s.traceName, s.cursorName, s.pointNumber)
            break
    endswitch

    return statusCode
End

Function NewUpdateControls(graphName, traceName, cursorName, pointNumber)
    String graphName    //"ExampleSubGraph#G0"
    String traceName, cursorName
    Variable pointNumber

    WAVE xx=root:xx
    WAVE/T text=root:text
    String hostGraph= StringFromList(0,graphName,"#") // removes #G0
    SetVariable xValue,win=$hostGraph,value= xx[pointNumber]
    SetVariable textValue,win=$hostGraph,value= text[pointNumber]

    // I don't use wx and wy, but you might
    Wave/Z wy= TraceNameToWaveRef(graphName,traceName)
    Wave/Z wx= XWaveRefFromTrace(graphName,traceName)
   
    TextBox/W=$hostGraph/C/N=readout "point number = "+num2istr(pointNumber)

    Print "Y value= ", wy[pointNumber]
End