Change System Cursor

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello
I want to change the Hand system cursor, with the hand with shadow
I used this code in Delphi some years ago:
<delphi>
IDC_HAND = MakeIntResource(32649);
Screen.Cursors[crHandPoint] := LoadCursor(0, IDC_HAND);
</delphi>

But in C# it doesn't work, the cursor doesn't change
<c#>
int IDC_HAND = 32649;
IntPtr hc = LoadCursor( IntPtr.Zero, IDC_HAND);
SetSystemCursor( hc, (uint)Cursors.Hand.Handle) )
</c#>

Is there any way to change the system cursor with the other one?

Thanks
 
Hi ariel754,

Thanks for your post.

Based on my understanding, you want to change the system wide cursor with
your own cursor icon.

Your code is almost right, except that we should pass a system defined
const for the SetSystemCursor second parameter instead of
Cursors.Hand.Handle, which is the runtime handle of the cursor.

The modified code snipet listed below:

[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);

[DllImport("user32.dll")]
static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);

private int IDC_UPARROW=32516;
private const uint OCR_NORMAL=32512;
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr hcursor = LoadCursor(IntPtr.Zero, IDC_UPARROW);
bool ret_val = SetSystemCursor(hcursor, OCR_NORMAL);
}
This works well on my side, for your information.

Additionally, in Windows, many windows defined their own cursor in its own
WndProc when processing WM_SETCURSOR message, so in these windows, our
default system cursor will be replaced by there own cursor.
=====================================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi ariel754,

Does my reply make sense to you? Is your problem resolved? Please feel free
to feedback, thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
private void button1_Click(object sender, System.EventArgs e)
{
IntPtr hcursor = LoadCursor(IntPtr.Zero, IDC_UPARROW);
bool ret_val = SetSystemCursor(hcursor, OCR_NORMAL);
}
This works well on my side, for your information.

yes this works, but for some reason the new cursor is the same Hand _without
the shadow_ :(
it seams I need to call CopyCursor but there isn't any way in C#, is that
possible? or is there any other way to set the cursor to the Hand with the
shadow?

Thanks!
 
Back
Top