-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCursorManager.cs
More file actions
52 lines (44 loc) · 1.2 KB
/
Copy pathCursorManager.cs
File metadata and controls
52 lines (44 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
namespace OsuCursorOverlay;
public sealed class CursorManager : IDisposable
{
private bool _disposed = false;
public CursorManager()
{
AppDomain.CurrentDomain.ProcessExit += (_, _) => RestoreSystemCursors();
}
public void HideSystemCursors()
{
foreach (var cursorId in NativeMethods.CursorTypeIds)
{
var blank = CreateBlankCursor();
if (blank != IntPtr.Zero)
{
NativeMethods.SetSystemCursor(blank, cursorId);
}
}
}
public void RestoreSystemCursors()
{
NativeMethods.SystemParametersInfoW(NativeMethods.SPI_SETCURSORS, 0, IntPtr.Zero, 0);
}
public void Dispose()
{
if (!_disposed)
{
RestoreSystemCursors();
_disposed = true;
}
}
private static IntPtr CreateBlankCursor()
{
byte[] andMask = new byte[128];
byte[] xorMask = new byte[128];
// All bits set to 1 (transparent)
for (int i = 0; i < 128; i++)
{
andMask[i] = 0xFF;
xorMask[i] = 0x00;
}
return NativeMethods.CreateCursor(IntPtr.Zero, 0, 0, 32, 32, andMask, xorMask);
}
}