Rectangle appears on hooked graph

I work on 3D spectral images, such that I create a 2D image from the 3D wave using sumBeams (see below). Then I add a hook function to the graph that allows me to click anywhere on the image and the spectrum at that x-y position is being displayed. It happens quite often that suddenly a rectangle appears on the image as if I had clicked and dragged the mouse (see attached png).

I can reproduce this behaviour with:

function DisplayImage(w)
    wave w
   
    DoWindow Image
    if (V_flag ==0)
        NewImage/K=1/N=Image  w
        SetWindow Image,hook(s)=myHook 
    endif
end


Function myHook(s)
    STRUCT WMWinHookStruct &s
   
    wave cube = root:cube
   
    // store where the mouse is currently
    variable xx = round ( AxisValFromPixel("", "Bottom", s.mouseLoc.h) )
    variable yy = round ( AxisValFromPixel("", "Left", s.mouseLoc.v) )
   
    variable maxX = DimSize(cube, 0)
    variable maxY = DimSize(cube, 1)
   
    switch(s.eventCode)
       
        case 3:                 // handle left mouse click  
       
            // prevent error when clicking outside of image
            if (xx >= maxX || yy >= maxY || xx < 0  || yy < 0)
                break
            endif
               
            MatrixOp/O CrsSpec = beam(cube, xx, yy)
            wave CrsSpec =  root:CrsSpec
            doWindow/F PointSpectrum
           
            if (V_flag==0)
                Display/K=1/N=PointSpectrum CrsSpec
            endif
           
            break
                       
    endswitch
   
    return 0
End


Then execute

Make/U/B/N=(200,200,200) cube = abs(enoise(1))
MatrixOP/O M_SumImage = sumBeams(Cube)
DisplayImage(M_SumImage)


It may take 30-40 clicks to get it, but it occurs. This is under Mac OS 10.8.5 and IGOR 6.34A.
Is there something in my code that may cause this or possibly a bug?


EDIT: This does not seem to be an issue on Windows and on Mac it seems to be more likely to occur when I first increase the image by dragging the graph window to a larger size

You are seeing a Marquee.

Try doing one of these things from your hook function when you want the click that your hook function handles to not be used for its normal purpose, which might be starting a marquee:

1. Return 1 from your hook function. This tells Igor that your hook function handled the click and that the click should not continue to be handled by the event system.
2. Call GetMarquee/W=$(s.winName) 0, 0, 0, 0. This will clear any marquee that is on the graph already.

I don't think #2 will actually solve your problem, however, since the click is probably used to start a marquee after your hook function runs.

You might also change your hook function to require more than just a click so that you don't prevent the regular Igor features such as marquee generation from being possible. For example, you could require a shift-click in the graph by only handling the event when s.eventMod &  0x02 is true.
aclight wrote:

1. Return 1 from your hook function. This tells Igor that your hook function handled the click and that the click should not continue to be handled by the event system.


I think that does it! Lots of clicking - no marquee!

aclight wrote:

You might also change your hook function to require more than just a click so that you don't prevent the regular Igor features such as marquee generation from being possible. For example, you could require a shift-click in the graph by only handling the event when s.eventMod &  0x02 is true.


I thought about this but wasn't sure how to do it. Might change it now!

Thanks for the quick support!!