简体   繁体   中英

How to hide and disable cursor globally?

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?

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.

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM