Set the cursor, bypassing cursor magnification - macos

I'd like to set the cursor in a Mac application for a specific view without that cursor being subject to the Cursor Magnification setting in Universal Access.
As an example, I'd like to set the cursor to a preview of the brush the user has selected. It should be the size of the brush, so that the user knows what how big their brush-stroke will be. Cursor magnification throws this off; I might as well just have the arrow cursor at that point.
I do not want to change (and have to restore) the cursor magnification setting itself. I want specific custom cursors to not be subject to it.
Hiding the cursor and drawing a fake cursor within my view doesn't work, since it'll be clipped at the view/window edges.
I'd prefer a solution that lets me use NSCursor, but seeing no obvious solution in that class, I'd be willing to accept another solution that uses something lower-level.

Hiding the cursor and drawing a fake cursor within my view doesn't work, since it'll be clipped at the view/window edges.
Then an overlay window is your next best bet, I think.

Related

Restrict mouse movement over a specified window handle

I'm looking to simulate a kiosk mode for Safari on Windows. OSX will not work with my input hardware and Chrome's GPU acceleration is too slow for the machine I'm using.
The only plausible solution [so far] is to run Safari and send an F11 (fullscreen) keystroke, but prevent the URL bar from expanding when the mouse reaches the top pixels of the screen.
I've looked and can't seem to find any good solution and would like to know if I can restrict the cursor movement from reaching the top pixel of the screen?
If anyone has any other solutions, that would be great!
You can use the ClipCursor function to do this.
Confines the cursor to a rectangular area on the screen. If a subsequent cursor position (set by the SetCursorPos function or the mouse) lies outside the rectangle, the system automatically adjusts the position to keep the cursor inside the rectangular area.
You can poll the cursor position and correct it using a timer, but this is not ideal. You could also cover the top bar by a transparent topmost window. This way, input will never reach the top bar.
EDIT: If Internet explorer is an option you have the possibility to use the COM object to embed what you need in a custom application. Other browsers might have similar APIs, but I'm not familiar with them.

Cursor flashing on the non-client area when using IDirect3DDevice9::SetCursorProperties

I have an application running under Direct3D9. The application is using the Direct3D HW cursor API (IDirect3DDevice9::SetCursorProperties et al.) to control the cursor. Almost everything works fine:
when inside of the application window, the cursor specified by SetCursorProperties is shown
when outside of the application window, normal OS cursor is displayed as needed by desktop or other windows
The problem is with the non-client area of my window (the title bar, screen edges). When moving in the non-client area, the cursor corresponding to the function of the area is breifly shown, but once I stop moving, the cursor set in SetCursorProperties is shown again.
What is the correct way to use IDirect3DDevice9::SetCursorProperties so that I get the default OS cursors on my window non-client area?
After experimenting with various things, a following change in the application has solved the issue for me:
In a window procedure, when a WM_SETCURSOR is received, remember a result of a condition (lParam&0xffff)==HTCLIENT in a global variable CursorInClient
When the global variable CursorInClient is false, avoid calling IDirect3DDevice9::ShowCursor

How to set the cursor in kEventControlSetCursor?

I want to be able to change the appearance of the mouse cursor as it moves over various hot spots in my view's and it seems to me that I should be doing that in the kEventControlSetCursor handler (which I can get). The function "SetCursor" is deprecated, which leads to the question, what do I call to actually change the cursor?
And is there some standard list of cursors I can use? Things like horizontal and vertical arrows? I beam?
Use SetThemeCursor or SetAnimatedThemeCursor, which are both part of the Appearance Manager.
And is there some standard list of cursors I can use? Things like horizontal and vertical arrows? I beam?
The standard cursors, including those, are all you can use in the Appearance Manager; it provides no way to set a custom cursor.
The modern replacement for all three functions is Cocoa's NSCursor, which provides standard cursors and supports custom cursors.

How to tell if mouse pointer icon changed

I'm writing a screen recording app for Windows in Delphi 7 and wish to know when the mouse pointer changes in my app (like from a normal pointer to a resize pointer, etc).
Currently what I'm doing is painting the mouse pointer onto an in-memory bitmap everytime the mouse moves (and on a timer) and doing a pixel by pixel comparison of it with the last bitmap I painted.
Though the comparision is fairly quick (about 2-5ms) because it's happening so often (every mouse move) it adds up. I figure there has to be a faster and less complicated way!
You have a handle to the cursor, right? If it's the same handle value you had before, then I think it's reasonable to assume it looks the same, too. If the cursor looks different, it will have a different handle value.
That should certainly be true for the standard system cursors. If the application you're recording is creating new cursors while it's running, then maybe it would be able to update the appearance of the current cursor without actually making a new cursor object in the OS (and thus keeping the same handle value), but I don't think that's likely, especially since SetCursor exits immediately when the cursor hasn't changed, and I expect the API function doesn't do the graphical comparison you're trying to avoid, either. It just compares the HCursor value.

Win32 WM_SETCURSOR, WM_MOUSEMOVE always in pair?

I'm working on a Win32 control. There could be hundreds of "items" on this control. Those are not windows, but internal objects (eg: rectangles). Depending on the mouse position I want to change the mouse cursor. That is fine, I can use WM_SETCURSOR.
At the same time based on mouse move I want to display a status bar which shows details about the object currently under the mouse. For that I can use WM_MOUSEMOVE.
Because there could be hundreds of items, traveling all of them to find one under the mouse, well it's not efficient, especially two times (one for set cursor, one for mouse move).
To make it short, do you know if WM_SETCURSOR and WM_MOUSEMOVE are ALWAYS in pair? In that case I can calculate what I want during WM_SETCURSOR. The other option would be to set the mouse cursor during WM_MOUSEMOVE, but as far as I know that it's not a good solution (will flicker).
Thanks
While they might currently always come as a matched pair, you probably can't rely on this behaviour.
You can set the cursor during WM_MOUSEMOVE (using SetCursor), and it won't flicker, as long as (IIRC), you return TRUE from WM_SETCURSOR without doing anything (i.e. you eat the message), and your window doesn't have a class cursor assigned to it.
You might also try GetMessagePos() (gives cursor screen coordinates), then MapWindowPoints() and see if it's in hot rectangle, or something similar.
Most important of all is that your window message handlers shouldn't worry about holding or calculating anything. You should simply signal your application's logic that the mouse is potentially over new area and make it find the object(s). Once you find the hot area (or more than one), cache its (their) boundaries and check the following mouse moves against those. Once the mouse moves out from one of them, you can rebuild your hot-object-list.
You don't have to be hunting for the hot area all over the control on every mouse move.
In case when there can be many objects sharing the same area, there's the question of z-order. Think about it when you're creating those objects and handle their movement.
Also you should think about an efficient data structure holding the object coordinates so you don't have to check every single object every time you're looking for the hot one.
Just my two euros. ;)
Is there any way to cache the last item that was found, and shortcut the lookup if the cursor is in the same place? That would be the most robust solution.

Resources