how to change the cursor style in all form?

Dark_Elf

New member
Joined
Sep 11, 2024
Messages
2
Programming Experience
1-3
I want to write a tool software, when I click on the status bar icon of this tool software, it displays the coordinates and color values of the mouse cursor position, I have already realized the specific function, but I want to set the mouse cursor style to cross cursor style in the process of capturing the desktop coordinates, because at this time, the mouse cursor is not in my program window, so I simply change the form control. Cursor style to cross doesn't work, I checked the solution on stackoverflow, by modifying the custom default cursor style file on the registry, and then refreshing the system's cursor settings, but it doesn't work, the program will still revert to the default arrow cursor on other windows, how should I achieve my purpose, can someone tell me?

Below is a solution I found on stackoverflow, however it doesn't solve the problem.
1726048643752.png


I want to add the action of changing the mouse cursor in the following event:

1726048697475.png
 
Please don't post just pictures of code. You can post a picture as well if it adds value, which it doesn't in this case, but you should ALWAYS post the code as text, formatted as code. We can't copy text from a picture.
 
Please don't post just pictures of code. You can post a picture as well if it adds value, which it doesn't in this case, but you should ALWAYS post the code as text, formatted as code. We can't copy text from a picture.

Sorry, I'm not familiar with the community's publishing rules, I'll pay attention next time.
 
Changing the cursor in the registry is not the correct approach.

As I vaguely recall from my Win32 programming days, to do what you want to do, you need to set the mouse capture, and then change the cursor while you have captured the mouse. My reading of the SetCursor() documentation seems to bear this out:
The cursor is a shared resource. A window should set the cursor shape only when the cursor is in its client area or when the window is capturing mouse input. In systems without a mouse, the window should restore the previous cursor before the cursor leaves the client area or before it relinquishes control to another window.
(emphasis mine)

I think if you can find the source code for the Win32 API DoDragDrop() you will find that internally it calls SetCapture() and then makes various SetCursor() calls depending on what the drop target will accept.
 
Also your title is misleading. You are asking how to change the cursor style in "all form" which means that you just want to change the cursor for your forms. What you are describing though is that you want to change the cursor style for all windows regardless whether the window belongs to your program or some other program.
 
Back
Top Bottom