Mouse Tracking C++ How To

Hi,

I am wondering what is the best way to track mouse clicks. Imagine a simple tool like “Brush” in Photoshop…I want specific actions to be performed on mouse click and specific actions to performed when the mouse button is held down and the mouse is moved (these actions would appear in a certain time interval I guess)…

What is the best way to do this?

Greetings,
Milos

The easiest is to can subclass CRhinoMouseCallback to be notified of mouse clicks (see the header for more info). But: note that Rhino sometimes does not report a mouse-up or mouse-down event when one does happen, so I would not advise tracking the mouse state with it. Then you’re better off by __hook/__unhook into the windows mouse tracking system.

See for example http://www.codeproject.com/Articles/67091/Mouse-and-KeyBoard-Hooking-utility-with-VC

I couldn’t have said this any better…

Thanks!

The example does seem a bit confusing…but I could give it a try… I thought there are simple/clearer MFC functions that control mouse events…hence simple Rhino functions derived from them. Because what I am trying to do, Rhino already does every time you hold a button to grab/move objects, or to rotate, zoom,pan…so it has to be used by many of your functions (?)…and that is the only information i need, if the button is down/up and what are the coordinates of the cursor…just like the function called when I grab an object with the left click and move it until I release the button…is CRhinoMouseCallback used for this?

These guys basically managed to control it in the way I want: http://www.food4rhino.com/project/paint3d-meshes-rhino?etx

Greetings,
Milos

Have you tried contacting them?

The easy way to control the mouse, in Rhino, is to use the CRhinoGetObject class (for object picking) and the CRhinoGetPointclass (for point picking). Each of these classes has numerous overridable members to control whether or not the “action” takes place on mouse up or down. In the case of CRhinoGetObject, you can also watch for mouse down and mouse move.

Beyond this is the CRhinoMouseCallback class. This class isn’t used by core Rhino at all, so you might find some issues (mentioned by Menno above). But in general, it works pretty well to get mouse messages outside of a command.

If neither of these methods work for you, your remaining alternative is to hook the mouse. There is a lot of information about doing this (in the Internet). But it all involved the SetWindowsHookEx Win32 API.