Ejemplo n.º 1
0
        public static void SetSystemCursor(Cursor cursor)
        {
            // Get previous cursor
            var pci = new CURSORINFO();

            pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
            GetCursorInfo(out pci);

            // Get previous cursor type (the one to be replaced)
            _previousCursorType = GetCursorType(pci);

            // Copy previous cursor because next SetSystemCursor might destroy it
            _previousCursor = CopyImage(pci.hCursor,
                                        (uint)CopyImageType.IMAGE_CURSOR,
                                        Cursors.Default.Size.Width,
                                        Cursors.Default.Size.Height,
                                        (uint)FUFlags.LR_COPYFROMRESOURCE);

            // Copy the cursor to set
            IntPtr newCursor = CopyImage(cursor.Handle,
                                         (uint)CopyImageType.IMAGE_CURSOR,
                                         cursor.Size.Width,
                                         cursor.Size.Height,
                                         (uint)FUFlags.LR_COPYFROMRESOURCE);

            // Set the cursor in replacement of the current one
            bool r = SetSystemCursor(newCursor, (uint)_previousCursorType);

            if (!r)
            {
                Console.WriteLine("Error: " + Marshal.GetLastWin32Error());
            }
        }
Ejemplo n.º 2
0
 public static extern bool SetSystemCursor(IntPtr hcur, OCR_SYSTEM_CURSORS id);
Ejemplo n.º 3
0
        public static void SetSystemCursor(Cursor cursor)
        {
            // Get previous cursor
            var pci = new CURSORINFO();
            pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
            GetCursorInfo(out pci);

            // Get previous cursor type (the one to be replaced)
            _previousCursorType = GetCursorType(pci);

            // Copy previous cursor because next SetSystemCursor might destroy it
            _previousCursor = CopyImage(pci.hCursor,
                                        (uint)CopyImageType.IMAGE_CURSOR,
                                        Cursors.Default.Size.Width,
                                        Cursors.Default.Size.Height,
                                        (uint)FUFlags.LR_COPYFROMRESOURCE);

            // Copy the cursor to set
            IntPtr newCursor = CopyImage(cursor.Handle,
                                         (uint)CopyImageType.IMAGE_CURSOR,
                                         cursor.Size.Width,
                                         cursor.Size.Height,
                                         (uint)FUFlags.LR_COPYFROMRESOURCE);

            // Set the cursor in replacement of the current one
            bool r = SetSystemCursor(newCursor, (uint)_previousCursorType);

            if (!r)
                Console.WriteLine("Error: " + Marshal.GetLastWin32Error());
        }
Ejemplo n.º 4
0
 public static extern IntPtr LoadCursor(IntPtr hInstance, OCR_SYSTEM_CURSORS lpCursorName);
Ejemplo n.º 5
0
 public static extern bool SetSystemCursor(IntPtr hcur, OCR_SYSTEM_CURSORS id);