I have two questions:
- 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.
- How to disable mouse operations for all programs? I use SetWindowsHookEx to hook mouse and prevent other progr开发者_JAVA百科ams 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?
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.
You can use SetCursorPos
to keep the cursor centered in your window. Please, don't hide my mouse cursor, it's not yours.
Hiding the cursor globally is difficult. 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.
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.
精彩评论