I've been trying to do so and couldn't make it, this is what I got to :
[DllImport("user32.dll")]
static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll", EntryPoint = "GetCursorInfo")]
public static extern bool GetCursorInfo(out CURSORINFO pci);
[DllImport("user32.dll", EntryPoint = "CopyIcon")]
public static extern IntPtr CopyIcon(IntPtr hIcon);
[StructLayout(LayoutKind.Sequential)]
public struct CURSORINFO
{
public Int32 cbSize; // Specifies the size, in bytes, of the structure.
public Int32 flags; // Specifies the cursor state. This parameter can be one of the following values:
public IntPtr hCursor; // Handle to the cursor.
public POINT ptScreenPos; // A POINT structure that receives the screen coordinates of the cursor.
}
public void etc()
{
IntPtr hwndic = new IntPtr();
CURSORINFO curin = new CURSORINFO();
curin.cbSize = Marshal.SizeOf(curin);
if (GetCursorInfo(out curin))
{
if (curin.flags == CURSOR_SHOWING)
{
hwndic = CopyIcon(curin.hCursor);
SetSystemCursor(hwndic, OCR_NORMAL);
}
}
}
The problem is that the copied icon sometimes is different than the default mouse icon, if it catches it on waiting position for example then it might give me the mouse waiting icon.
I wish to get the default cursor icon (the icon at idle) of the running system, how can I do so?
Thanks in advance.
I've solved my issues, after some research I got to something interesting that would probably work all the time.
Instead of trying to save a cursor's icon and loading it I thought of a different idea.
I've noticed that whenever I change a cursor icon (lets say using a code, to some random icon) then whenever I go to the windows cursor settings the icon is not changed there, but there's no apply button to apply the settings I had before, because windows thinks I'm using those settings.
So I changed the settings to some random other settings without applying and returned to the settings I had before and applied, doing so resetted my cursor to its original cursor, before any of the changes.
Therefore what windows was just doing is "refreshing" the mouse, so I went that way, maybe if I can force a refresh everything would be perfect, and so I found a way to do it, using this function :
As I've watched msdn I've found something interesting in its parameters, the parameter "SPI_SETCURSORS (0x57)", and I quote :
"Reloads the system cursors. Set the uiParam parameter to zero and the pvParam parameter to NULL."
So I've tried it, and it worked, example of the process :
I thought it'd take me 5 minutes to do something like this... I hope it'll help you guys, and I really appreciate the comments trying to help me.