-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
119 lines (93 loc) · 4.01 KB
/
NativeMethods.cs
File metadata and controls
119 lines (93 loc) · 4.01 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System.Runtime.InteropServices;
namespace CapsNumTray;
internal static class NativeMethods
{
// Shell_NotifyIconW
public const uint NIM_ADD = 0x00;
public const uint NIM_MODIFY = 0x01;
public const uint NIM_DELETE = 0x02;
public const uint NIM_SETVERSION = 0x04;
public const uint NIF_MESSAGE = 0x01;
public const uint NIF_ICON = 0x02;
public const uint NIF_TIP = 0x04;
public const uint NIF_SHOWTIP = 0x80;
public const uint NOTIFYICON_VERSION_4 = 4;
// Window messages
public const uint WM_TRAY = 0x8010;
public const int WM_LBUTTONUP = 0x0202;
public const int WM_RBUTTONUP = 0x0205;
public const int WM_CONTEXTMENU = 0x007B;
// Icon loading
public const uint IMAGE_ICON = 1;
public const uint LR_LOADFROMFILE = 0x0010;
// Virtual keys
public const byte VK_CAPITAL = 0x14;
public const byte VK_NUMLOCK = 0x90;
public const byte VK_SCROLL = 0x91;
public const uint KEYEVENTF_EXTENDEDKEY = 0x0001;
public const uint KEYEVENTF_KEYUP = 0x0002;
// Low-level keyboard hook
public const int WH_KEYBOARD_LL = 13;
public const int WM_KEYDOWN = 0x0100;
public const int WM_KEYUP = 0x0101;
public const int WM_SYSKEYDOWN = 0x0104;
public const int WM_SYSKEYUP = 0x0105;
public delegate nint LowLevelKeyboardProc(int nCode, nint wParam, nint lParam);
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Shell_NotifyIconW(uint dwMessage, ref NOTIFYICONDATAW lpData);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
public static extern uint RegisterWindowMessage(string lpString);
[DllImport("user32.dll")]
public static extern uint GetDpiForWindow(nint hwnd);
[DllImport("user32.dll")]
public static extern uint GetDpiForSystem();
[DllImport("user32.dll")]
public static extern nint LoadImage(nint hInst, string name, uint type, int cx, int cy, uint fuLoad);
[DllImport("user32.dll")]
public static extern nint LoadIcon(nint hInstance, nint lpIconName);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool DestroyIcon(nint hIcon);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(nint hWnd);
[DllImport("user32.dll")]
public static extern short GetKeyState(int nVirtKey);
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, nuint dwExtraInfo);
[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool Beep(uint dwFreq, uint dwDuration);
[DllImport("user32.dll", SetLastError = true)]
public static extern nint SetWindowsHookEx(int idHook, LowLevelKeyboardProc lpfn, nint hMod, uint dwThreadId);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool UnhookWindowsHookEx(nint hhk);
[DllImport("user32.dll")]
public static extern nint CallNextHookEx(nint hhk, int nCode, nint wParam, nint lParam);
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
public static extern nint GetModuleHandle(string? lpModuleName);
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NOTIFYICONDATAW
{
public uint cbSize;
public nint hWnd;
public uint uID;
public uint uFlags;
public uint uCallbackMessage;
public nint hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szTip;
public uint dwState;
public uint dwStateMask;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szInfo;
public uint uVersion; // union with uTimeout
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szInfoTitle;
public uint dwInfoFlags;
public Guid guidItem;
public nint hBalloonIcon;
}
}