Repository navigation
Expand file tree
/
Copy pathNativeMethods.cs
More file actions
212 lines (165 loc) · 8.04 KB
/
Copy pathNativeMethods.cs
File metadata and controls
212 lines (165 loc) · 8.04 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace PowerProut;
public static class NativeMethods
{
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int X;
public int Y;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct NOTIFYICONDATA
{
public int cbSize;
public IntPtr hWnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public IntPtr hIcon;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
public string szTip;
public int dwState;
public int dwStateMask;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public string szInfo;
public int uTimeoutOrVersion;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
public string szInfoTitle;
public int dwInfoFlags;
public Guid guidItem;
public IntPtr hBalloonIcon;
}
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(string lpClassName, string? lpWindowName);
[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hWnd, out RECT lpRect);
[DllImport("user32.dll", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
[DllImport("user32.dll", EntryPoint = "GetWindowLongPtr", SetLastError = true)]
public static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
[DllImport("user32.dll")]
public static extern uint GetDpiForWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("user32.dll")]
public static extern bool SetLayeredWindowAttributes(IntPtr hwnd, uint crKey, byte bAlpha, uint dwFlags);
[DllImport("dwmapi.dll")]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
[DllImport("user32.dll")]
public static extern bool GetPhysicalCursorPos(out POINT lpPoint);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern IntPtr GetShellWindow();
[DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool AddClipboardFormatListener(IntPtr hwnd);
[DllImport("user32.dll")]
public static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
[DllImport("Comctl32.dll", SetLastError = true)]
public static extern bool SetWindowSubclass(IntPtr hWnd, SUBCLASSPROC pfnSubclass, uint uIdSubclass, IntPtr dwRefData);
[DllImport("Comctl32.dll", SetLastError = true)]
public static extern IntPtr DefSubclassProc(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam);
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern int PickIconDlg(IntPtr hwndOwner, StringBuilder lpstrFile, int nMaxFile, ref int lpdwIconIndex);
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern uint ExtractIconEx(string lpszFile, int nIconIndex, out IntPtr phiconLarge, out IntPtr phiconSmall, uint nIcons);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool DestroyIcon(IntPtr hIcon);
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
public static extern bool Shell_NotifyIcon(uint dwMessage, ref NOTIFYICONDATA lpData);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr CreatePopupMenu();
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool AppendMenu(IntPtr hMenu, uint uFlags, uint uIDNewItem, string lpNewItem);
[DllImport("user32.dll", SetLastError = true)]
public static extern int TrackPopupMenu(IntPtr hMenu, uint uFlags, int x, int y, int nReserved, IntPtr hWnd, IntPtr prcRect);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool GetCursorPos(out POINT lpPoint);
[DllImport("user32.dll")]
public static extern bool PostMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
public delegate IntPtr SUBCLASSPROC(IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam, uint uIdSubclass, IntPtr dwRefData);
// Constants
public const int GWL_STYLE = -16;
public const int GWL_EXSTYLE = -20;
public const int GWLP_HWNDPARENT = -8;
public const int WS_CAPTION = 0x00C00000;
public const int WS_THICKFRAME = 0x00040000;
public const int WS_MINIMIZEBOX = 0x00020000;
public const int WS_MAXIMIZEBOX = 0x0010000;
public const int WS_SYSMENU = 0x00080000;
public const long WS_EX_APPWINDOW = 0x00040000L;
public const long WS_EX_TOOLWINDOW = 0x00000080L;
public const long WS_EX_TOPMOST = 0x00000008L;
public const long WS_EX_NOACTIVATE = 0x08000000L;
public const int WS_EX_LAYERED = 0x80000;
public const int LWA_ALPHA = 2;
public const int SW_HIDE = 0;
public const int SW_SHOWNA = 8;
public static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
public const uint SWP_NOMOVE = 0x0002;
public const uint SWP_NOSIZE = 0x0001;
public const uint SWP_SHOWWINDOW = 0x0040;
public const uint SWP_NOACTIVATE = 0x0010;
public const uint SWP_FRAMECHANGED = 0x0020;
public const int DWMWA_NCRENDERING_POLICY = 2;
public const int DWMNCRP_DISABLED = 1;
public const int DWMWA_TRANSITIONS_FORCEDISABLED = 3;
public const int DWMWA_WINDOW_CORNER_PREFERENCE = 33;
public const int DWMWCP_DONOTROUND = 1;
public const int DWMWA_SHADOW_POLICY = 7;
public const int DWMWSP_DISABLED = 1;
public const byte VK_CONTROL = 0x11;
public const byte VK_V = 0x56;
public const byte VK_LWIN = 0x5B;
public const byte VK_D = 0x44;
public const uint KEYEVENTF_KEYUP = 0x0002;
public const uint WM_CLIPBOARDUPDATE = 0x031D;
public const uint WM_COMMAND = 0x0111;
public const uint WM_TRAYICON = 0x8000 + 100;
public const int NIM_ADD = 0x00000000;
public const int NIM_MODIFY = 0x00000001;
public const int NIM_DELETE = 0x00000002;
public const int NIF_MESSAGE = 0x00000001;
public const int NIF_ICON = 0x00000002;
public const int NIF_TIP = 0x00000004;
public const int WM_LBUTTONDBLCLK = 0x0203;
public const int WM_RBUTTONUP = 0x0205;
public const int WM_CONTEXTMENU = 0x007B;
public const uint MF_STRING = 0x00000000;
public const uint MF_SEPARATOR = 0x00000800;
public const uint MF_RIGHTBUTTON = 0x0002;
public const uint TPM_RETURNCMD = 0x0100;
public const uint TPM_RIGHTBUTTON = 0x0002;
[DllImport("shell32.dll", SetLastError = true)]
public static extern int SetCurrentProcessExplicitAppUserModelID([MarshalAs(UnmanagedType.LPWStr)] string AppID);
[DllImport("user32.dll")]
public static extern bool MessageBeep(uint uType);
[DllImport("user32.dll")]
public static extern bool LockWorkStation();
public const uint MB_OK = 0x00000000;
public const uint MB_ICONASTERISK = 0x00000040;
public const uint MB_ICONEXCLAMATION = 0x00000030;
public const uint MB_ICONHAND = 0x00000010;
public const uint MB_ICONQUESTION = 0x00000020;
}