Window Hook Question

Hi,

Working on an interface for image analysis using imageGLCM. I am examine the effect of the image subset  size on the parameters and to that end I use the cursor location and take several different boxes around the cursor location and calculate the parameters.  All well and good with some subtleties thrown in for good measure.

The interface works off a window hook using a mouseup key to do the calculation.  I am not using cursor moved because the base is an image and cursormoved would force recalculations as the cursor is dragged.  In my examination I would like to set a marker where the cursor was prior to the move.  The intent here is that I store the previous sets of calculations and then the user (me) can compare the results at two places on an image.  To that end I am trying to use the mouse down event to register the prior location. The thought process being as I move the cursor the first thing that happens is a mouse down event and when I release at the new location I have a mouse up event.  Obviously by the existence of the question/post this is not working as intended.  The mouse down event is not setting the location when I drag the cursor.  If I do mouse click on the image away from the cursor the point where the cursor currently resides is logged.  How should I accomplish my goal?

 

Function boxhook(s)
    STRUCT WMWinHookStruct &s

    Variable hookResult = 0

    switch(s.eventCode)
        case 3: //Mouse down origin point when coursor is moved
            wave prior_point
            prior_point[0][%x] = hcsr(A)
            prior_point[0][%y] = vcsr(A)
            hookresult =1

            break
        case 5:             // Mouseup - where cursor is released
            // Handle activate
            texture()
            hookresult=1
            break
           
    endswitch

    return hookResult       // 0 if nothing done, else 1
End

 

Andy

Could it be that the hookresult=1 in the mousedown event cuts off the call to your window hook at the mouseup event? Try leaving hookresult = 0 at the mousedown.

You need to use the mouseloc substructure of WMWinHookStruct together with AxisValFromPixel to figure out the start and end locations for the mouse drag.

Hi,

I made some modifications following Tony's suggestion, but alas no joy in Mudville.

If I click on the image away from the cursor then the points get set as expected, however if I do a mouse click on top of the cursor it does not set the point as expected.  I am wondering if in the background clicks are handled differently when you are on the cursor.

Andy

Function boxhook(s)
    STRUCT WMWinHookStruct &s

    Variable hookResult = 0

    switch(s.eventCode)
        case 3: //Mouse down origin point when coursor is moved
            wave prior_point
            prior_point[0][%x] = axisvalFromPixel("maininterface","top",s.mouseloc.h)
            prior_point[0][%y] = axisvalFromPixel("maininterface","left",s.mouseloc.v)
            hookresult =1

            break
        case 5:             // Mouseup - where cursor is released
            // Handle activate
            texture()
            hookresult=1
            break
           
    endswitch

    return hookResult       // 0 if nothing done, else 1
End

 

 

Rejiggered the workflow bit.  So instead of dragging the cursor, I do a mouse click where the new location will be. Works, but I could still like to get the cursor dragging flow to work since I think it is more natural and I am using hair cursors so the user has the advantage of seeing the scale positions during drag..  The replacement code.

Function boxhook(s)
    STRUCT WMWinHookStruct &s

    Variable hookResult = 0

    switch(s.eventCode)
        case 3: //Mouse down origin point when coursor is moved
            wave prior_point
            prior_point[0][%x] = hcsr(a)
            prior_point[0][%y] = vcsr(a)
            hookresult =1

            break
        case 5:             // Mouseup - where cursor is released
            cursor/I/F A,TEM,axisvalFromPixel("maininterface","top",s.mouseloc.h),axisvalFromPixel("maininterface","left",s.mouseloc.v)
            // Handle activate
            texture()
            hookresult=1
            break
           
    endswitch

    return hookResult       // 0 if nothing done, else 1
End

 

Oh, I misunderstood, you're moving cursor A, but want to use the mousedown and mouseup associated with the cursor moving instead of the cursormoved event. Seems reasonable that the hook function wouldn't receive the mousedown event that grabs the graph cursor. Can you not just keep track of the new cursor position when it is first placed and then at each mouseup event to figure out the previous 'resting position'? Or am I still missing something?

EDIT - you could check that the mouseup position corresponds to the current cursor position before saving a new 'resting position' to avoid saving on every mouseup, but I don't think it would hurt to keep overwriting the saved position for every mouseup, even if it isn't a cursor move.

Function boxhook(s)
    STRUCT WMWinHookStruct &s

    Variable hookResult = 0

    switch(s.eventCode)
        case 5:             // Mouseup - where cursor is released
            NVAR oldh
            NVAR oldv
           
            variable newh = hcsr(a)
            variable newv = vcsr(a)
           
            if (newh!=oldh || newv!=oldv)
                // do something with the two positions
                print "distance moved", sqrt((newh-oldh)^2 + (newv-oldv)^2)
            endif
           
            oldh = newh
            oldv = newv
           
            break
           
    endswitch

    return hookResult       // 0 if nothing done, else 1
End

 

I think this is a bug in Igor 9 -- mouse down events aren't firing when you click on a cursor. The cursor is consuming the mouse event before it can call the hook function. FWIW, this has already been fixed for Igor 10.

Hi Ben,

Thank you for that clarification. And you used that phrase" Igor 10" - starts to rub hands in glee. I won't ask when.

Andy