How to hide and disable cursor globally? - c++

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 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.

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.

Related

Is it possible to disable the light-blue mouse over highlighting on a QTreeWidgetItem?

I've a QTreeWidget and need to disable the mouse over highlighting on the childItems but not the click selection. The point here is, that I need to set this per Item because some are selectable. I was thinking about the QTreeWidget::itemEntered signal to check if the item should be highlighted or not but I can't get it to work because the description says
QTreeWidget mouse tracking needs to be enabled for this feature to
work.
and I can't figure out how.
So my questions for are: How can I enable mouse tracking?
Is there an easier way to disable the highlighting?
Simply invoke setMouseTracking() to enable mouse tracking for a specific widget.
I ran into this problem (I know this is an old post, but I might as well post my solution, since it can be useful for others).
I could not properly disable the mouse feedback while keeping the mouse tracking enabled, but I could make this feedback invisible. I'm using qss stylesheets, and I set the mousehover feedback color to transparent:
MyTreeWidget::item:hover {
background-color: transparent
}
It did the trick for me. Sadly it makes the feedback invisible all the time, rather than allowing to turn it off and on.
So as a next step, for when I needed it, I implemented my own feedback by using a delegate and overwritting the paint function.
The QTreeView overwrite mouseMoveEvent and sends mouse coordinates to the delegate. This way, the delegate can adapt what it does in paint to this position. It feels pretty heavy, and a bit dirty, but it works. Delegate should also allow to have different behavior for different items.
PS: If you're using a delegate, in most cases, that should be enough without the qss change. In my case it wasn't, because I call QStyledItemDelegate::paint in my overwritten paint method, so I inherited some unwanted behavior.

How do I get the mouse's position off the dialog continuously? (MFC)

My question is:
How do i continuously get the mouse's position even when it isn't on any dialogs, in mfc?
It depends on your specific requirements. If you need to direct mouse input temporarily to a control you can call SetCapture. This will request the system to send all mouse messages to a specific window until you not longer need it by calling ReleaseCapture, or you lose it, when another window gains input focus. The latter is signaled through a WM_CAPTURECHANGED message.
If, on the other hand, you need continuous information about mouse positions you can install a timer (SetTimer) and call GetCursorPos.
You can always install a mouse hook. It's a bit overkill, but, it will give you what you want.

How can I receive or be able to process mouseMoveEvent(s) outside my widget window?

I am writing Qt application which plays a fade-in animation whenever the mouse is moved to a certain area in the screen, and a fade out animation whenever the mouse is moved out of that same area.
I've already found a similar question here in stack overflow, however, it does not quite answer my question. (similar question here)
If I install an event filter to the application, will I be able to see ALL the events in the application even if it's outside my widget window?
If not, I am aware of an alternative involving QWidget::grabMouse() inside a reimplementation of leaveEvent(). But if I do so, will I be able to interact with anything OUTSIDE my application?
edit: though i am using the Qt library, my application is only for deployment to Windows.
I'm fairly the certain the answer is no, because events outside of your widgets are handled by the OSs window manager (and propagated onto whatever application is in that space).
However you can get the mouse position anywhere on the screen by calling QCursor::pos(), you could poll at regular intervals to find out where the mouse is.
You could try creating a completely transparent window that stays on top of the area where you want to receive mouse events, with the Qt::WindowStaysOnTopHint, Qt::FramelessWindowHint and Qt::ToolTip flags (the last one might prevent the window from receiving the focus), the Qt::WA_TranslucentBackground attribute and the mouse tracking enabled.
If you are on Windows, you can create a global hook to receive every mouse message (right before it's sent to the window under the mouse pointer). Unfortunately I don't know whether this functionality exists in other OSs.

Qt Custom Window

Pardon me, I am a newbie :)
Is it possible in Qt to create a custom window without borders but still draggable without holding down the Alt Key? I created a borderless window but in order to be able to drag it (on Linux) you have to hold down the alt key.
I was planning to create a window with rounded corners. Any one have any idea how to make this possible? Although, I think implementing the mouseMove, mousePress or something is a possible solution but I need some other solution.
Thanks
There is just one way to make the window manager move the window: Add a drag bar. If there is no drag bar, then your app must move the window itself by setting the new position (i.e. you must handle the mouse click+move events yourself).
The feature to move the window by pressing Alt is also a function of your window manager, not Qt.
Yes, there is a rounded window example somewhere using a clock which does this. Basically, you need to manage the mouse clicks yourself as Aaron says.
You may use QDecoration (for Embedded Linux) to make it: here is the example.
Detect that the mouse is held down on your window, then grab the events for the mouse moving around so you can move your window in sync with it. When user releases mouse button your task is over.

What is the most correct way to hide an autocomplete popup?

I'm developing a custom autocomplete control in pure WinApi, and the problem that I've encountered is that I don't know how to hide the popup window when clicked outside of the control (e.g. emulate the combobox dropdown behavior). How is it usually implemented? Should I use mouse capture? Thanks.
UPD: Tracking keyboard focus doesn't fit the bill since dragging the parent window around should also hide the dropdown.
UPD: Mouse capture doesn't work because it "captures mouse input either when the mouse is over the capturing window, or when the mouse button was pressed while the mouse was over the capturing window and the button is still down".
After reading this article I now believe that using SetWindowsHookEx and a WH_MOUSE hook is the way to go.
But maybe there is a simpler solution?
Autocomplete is native in Win32 api (Shell)
You don't need code.
(For source code of Windows Shell Autocomplete, see on Win32 group )