- Home /
How can I change system cursor in windows?
I want my application change cursor in windows when it's over some areas in my game. For example - always it's standart arrow and sometimes it's hand pointer. I tried do it with WINAPI using
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
static extern int GetWindowLong(System.IntPtr hWnd, int nIndex);
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern System.IntPtr LoadCursor(System.IntPtr hInstance, int lpCursorName);
[System.Runtime.InteropServices.DllImport("user32.dll")]
and do this
hcursor = LoadCursor(System.IntPtr.Zero, (int)IDC_STANDARD_CURSORS.OCR_HAND);
SetCursor(hcursor);
when I'm changing cursor
But it seems like OS changing it after me. I found this information
If your application must set the cursor while it is in a window, make sure the class cursor for the specified window's class is set to NULL. If the class cursor is not NULL, the system restores the class cursor each time the mouse is moved.
on MSDN, but i can't find how to do it. Maybe there is simplier ways control system cursor on windows with unity?
Answer by SkaredCreations · Dec 18, 2014 at 01:06 PM
Is there a particular reason why you don't want to use Cursor.SetCursor (to reset to default just pass: null)? You can easily find a "hand" cursor texture over the web...
It will not work if user defined on his system custom cursors. For example dinosaur(like win xp) ins$$anonymous$$d of system hand. I want use something like C#-way System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Hand;
Your answer
![](https://koobas.hobune.stream/wayback/20220613174332im_/https://answers.unity.com/themes/thub/images/avi.jpg)