views:

221

answers:

4

I have two questions:

  1. How to hide cursor for all programs? I tried to hide the cursor by using ShowCursor, but it only works in my program. The cursor still appears when moving cursor outside of my program.
  2. How to disable mouse operations for all programs? I use SetWindowsHookEx to hook mouse and prevent other programs to processing the mouse operations. I can hook the clicks, but the problem is that I can't hook the "move". When I move the mouse to menu or system buttons ("minimize/restore/close"), they are highlighted. This means they can still "see" the mouse.

Can anyone help me please?

+2  A: 

I shudder to wonder what you are trying to do, but the easiest way to do this, assuming you have an otherwise well behaving application, is to use SetCapture and ReleaseCapture when your app has a window in the foreground. You can also use ClipCursor(RECT *) to ensure that the cursor stays in a window under your control.

MSN
+1  A: 

Hiding the cursor globally is a bitch. You can create a fullscreen, transparent window and use ShowCursor on that, but of course it will also receive all mouse events then. Maybe it works for your particular case, though, since you also want to disable mouse input.

You can use SetWindowsHookEx with a WH_MOUSE_LL hook to disable mouse movement. If you return a nonzero value from your hook procedure, the mouse cursor will stay put.

All that being said, it does sound like you're trying to do something evil, or at least something your users might not like. I would advise to think twice whether this is really what you need.

Thomas
As I said, the WH_MOUSE_LL works for clicks, but not movement. When you move the mouse above the menu or system buttons, they still response to the mouse, although they are not clickable.BTW, I'm developing a remote control application which isn't evil :)
trudger
A: 

You can use SetCursorPos to keep the cursor centered in your window. Please, don't hide my mouse cursor, it's not yours.

avakar
A: 

The only legitimate reason (that I can imagine) for this would be to make a "kiosk". If that's your goal, search for, or re-state the question as a Kiosk question.

Chris Thornton
i had that thought too, but on our "kiosk" machines only one application is running....
Leslie