Hiding the system cursor

Prerequisites:

  • I am trying to create a mouse hiding application that hides a custom mouse from the screen after a certain time.
  • I tried many things, and using SetCursor only hides the mouse from the current application, mine should be able to sit the tray (for example) and still function.
  • I think I found a solution using SetSystemCursor, except for one problem.

MY PROBLEM:

  • I need to catch any kind of mouse cursor and replace the same mouse pointer.
  • When replacing the mouse, I need to specify the identifier of the type of mouse that I would like to replace with the mouse that the descriptor refers to, but none of the functions that I use provide me with the copied mouse identifier (or type).

MY QUESTION:

  • , 0,0, ? (Unhiding ).
  • 0,0 OCR_NORMAL mouse? ( .)
  • , /id , ?

:

[DllImport("user32.dll")]
public static extern IntPtr LoadCursorFromFile(string lpFileName);
[DllImport("user32.dll")]
public static extern bool SetSystemCursor(IntPtr hcur, uint id);
[DllImport("user32.dll")]
static extern bool GetCursorInfo(out CURSORINFO pci);

[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public Int32 x;
public Int32 y;
}

[StructLayout(LayoutKind.Sequential)]
struct CURSORINFO
{
public Int32 cbSize;        // Specifies the size, in bytes, of the structure. 
// The caller must set this to Marshal.SizeOf(typeof(CURSORINFO)).
public Int32 flags;         // Specifies the cursor state. This parameter can be one of the following values:
//    0             The cursor is hidden.
//    CURSOR_SHOWING    The cursor is showing.
public IntPtr hCursor;          // Handle to the cursor. 
public POINT ptScreenPos;       // A POINT structure that receives the screen coordinates of the cursor. 
}

private POINT cursorPosition;
private IntPtr cursorHandle;
private bool mouseVisible = false;
private const uint OCR_NORMAL = 32512;

//Get the current mouse, so we can replace it once we want to show the mouse again.
CURSORINFO pci;
pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
GetCursorInfo(out pci);
cursorPosition = pci.ptScreenPos;
cursorHandle = CopyIcon(pci.hCursor);

//Overwrite the current normal cursor with a blank cursor to "hide" it.
IntPtr cursor = LoadCursorFromFile(@"./Resources/Cursors/blank.cur");
SetSystemCursor(cursor, OCR_NORMAL);
mouseVisible = false;

//PROCESSING...

//Show the mouse with the mouse handle we copied earlier.
bool retval = SetSystemCursor(cursorHandle, OCR_NORMAL);
mouseVisible = true;
+3
2

. - .

+1

, setsystemcursor().

setsystemcursor() , , .

, , . - ShowCursor Win32.

: http://www.codeproject.com/Articles/12597/OSD-window-with-animation-effect-in-C

[DllImport("user32.dll")]
static extern int ShowCursor(bool bShow);

ShowCursor(false);
0

All Articles