Hook function on image disables menu functions

I have a hook function on an image, i.e.:


Function myHook(s)
	STRUCT WMWinHookStruct &s
	
	// get mouse position
	variable xpos =  AxisValFromPixel("", "Bottom", s.mouseLoc.h)
	variable ypos = AxisValFromPixel("", "Left", s.mouseLoc.v)
	
	switch(s.eventCode)
		
		case 3: 				// handle left mouse click 	
		
			print xpos, ypos		
			break
						
	endswitch
	
	return 1
End


and e.g.


make/N=(100,100) M_Image = p+q
NewImage/N=TestImage M_Image
SetWindow TestImage,hook(s)=myHook


Clicking on the image prints the mouse position on that image into the history.
Now I would like to use "Save Graphics" to save the image, but clicking onto that menu option (directly after clicking on the image) does not open the expected dialog.

Is this a bug or a feature?









Your hook function is returning 1 for every possible event. That includes some menu hook events, thereby disabling the menu. You should be experiencing a complete failure of virtually everything you can do with your image plot!

I suspect you want to return 0. Are you intending to disable the various things you can do with mouse clicks in a graph?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
johnweeks wrote: Your hook function is returning 1 for every possible event. That includes some menu hook events, thereby disabling the menu. You should be experiencing a complete failure of virtually everything you can do with your image plot!


Thanks for pointing this out! Yes, almost everything is disabled!

johnweeks wrote:
I suspect you want to return 0. Are you intending to disable the various things you can do with mouse clicks in a graph?


Rather yes. In the actual case, clicking on an image pixel reveals a spectrum that is stored along the z-axis of a 3D wave. There is no reason to do modifications to the graph. But good to know why the above happens!

Thanks!
You should probably go through the list of event codes and figure out exactly which you need to block.
Clicking on the image prints the mouse position on that image into the history.
Now I would like to use "Save Graphics" to save the image, but clicking onto that menu option (directly after clicking on the image) does not open the expected dialog.

Is this a bug or a feature?

Did you return 0 for event code 9 (enable menu) and 10 (menu)?

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
ChrLie wrote: Actually now I remember that I had issues with that function before and why I returned 1:

http://www.igorexchange.com/node/5677

If the choice is between 0 and 1 then I prefer the latter, since it took me more than a year to realise the effect ;-)

I think you need to be more selective in the events for which you return 1. For the previous problem I think you can return 1 just for mouse events:

	Variable retVal = 0
	switch(s.eventCode)
 
		case 3: 				// handle left mouse click 	
 
			print xpos, ypos	
			retVal = 1	
			break
		case 4:				// mouse moved
			retVal = 1
			break;
		case 5:				// mouse up
			retVal = 1
			break;
 
	endswitch

	return retVal

That will prevent the appearance of a marquee or any other mouse-related stuff. It will allow the menu events.

In Igor 7 there is a UI interaction control keyword with which you can disable features of a graph on a feature-by-feature basis.

John Weeks
WaveMetrics, Inc.
support@wavemetrics.com