Right click context menu with mouse coordinate info?

Hi folks,

I'd like to be able to right click a graph or image, then have a custom menu pop up such that can execute a function with the mouse-click coordinates available. 
 

I am thinking of a scenario like how you can natively right click a trace and then remove it etc. one specific example I'd like to implement is right clicking an image, then executing a seedfill operation at that point. It seems like lots of these bits and pieces are there (right click context menu, mouse click detection etc) but is it possible to tie it together this way?

 

Regards,

Scott

Yes, this is all very much possible. But the implementation depends somewhat on what exactly you want to do (for example, working with an image is different from traces etc.). Also, you already can right-click on a trace and remove it, since this is one of the built-in functions of Igor. Anyway, you might want to read up on GetLastUserMenuInfo.

DisplayHelpTopic "GetLastUserMenuInfo"

 

If you want to add an item to the regular contextual menus, execute:

DisplayHelpTopic "Contexual Menus That You Can Extend"

If adding to that menu isn't what you want, you probably need to set a window hook on each graph window you need to do this for and in your window hook you would handle either the mousedown or mouseup event, check that the right mouse button was pressed, and if so call PopupContextualMenu to present your menu. To read about window hooks, execute:

DisplayHelpTopic "Named Window Hook Functions"

Make sure that you have your window hook return 1 if Igor should ignore the event and 0 otherwise.

If you use the hook function approach, you can get the mouse coordinates from the WMWinHookStruct that is passed to your hook. If you extend the regular contextual menu, follow chozo's advice above to get the coordinates.

I suggest that you consider using a graph cursor as the input for the seed fill location instead of the mouse cursor. With the info window visible, you can move the cursor to a specific point more precisely and you can see the Z value at that point before you decide to use it as the seed. If you want to take this approach, you can call CsrInfo from either the hook or menu procedure call to get the location.

If you use a graph cursor, you would potentially need a different trigger to call ImageSeedFill. If the ImageSeedFill call is relatively fast, one way would be to call ImageSeedFill every time the graph cursor was moved. For an example of how to do this, execute:

DisplayHelpTopic "Graph-Specific Cursor Moved Hook"

Another approach would be to require a key stroke in the graph to trigger ImageSeedFill. You'd handle that in a named window hook as mentioned above. You might also want to write a panel so the user can supply the other inputs to seed fill and a button in the panel that does the seed fill based on the graph cursor when it's clicked.

Thank you both, this was all very helpful. I tried a few things and ended up building a control panel and handling it that way.