Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 01b383e

Browse files
committed
Port SystemEvents (Windows)
This enables the SystemEvents class by porting the existing Windows desktop code.
1 parent 3148e0e commit 01b383e

File tree

55 files changed

+1109
-577
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1109
-577
lines changed

src/Common/src/Interop/Windows/Interop.Errors.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ internal partial class Errors
7272
internal const int ERROR_BAD_IMPERSONATION_LEVEL = 0x542;
7373
internal const int ERROR_CANT_OPEN_ANONYMOUS = 0x543;
7474
internal const int ERROR_NO_SECURITY_ON_OBJECT = 0x546;
75+
internal const int ERROR_CLASS_ALREADY_EXISTS = 0x582;
7576
internal const int ERROR_TRUSTED_RELATIONSHIP_FAILURE = 0x6FD;
7677
internal const int ERROR_RESOURCE_LANG_NOT_FOUND = 0x717;
7778
internal const int EFail = unchecked((int)0x80004005);

src/Common/src/Interop/Windows/Interop.Libraries.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ internal static partial class Libraries
3030
internal const string WebSocket = "websocket.dll";
3131
internal const string WinHttp = "winhttp.dll";
3232
internal const string Ws2_32 = "ws2_32.dll";
33+
internal const string Wtsapi32 = "wtsapi32.dll";
3334
internal const string CompressionNative = "clrcompression.dll";
3435
}
3536
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal static partial class Interop
9+
{
10+
internal static partial class Kernel32
11+
{
12+
[DllImport(Interop.Libraries.Kernel32)]
13+
public static extern int GetCurrentThreadId();
14+
}
15+
}

src/Common/src/Interop/Windows/user32/Interop.Constants.cs

Lines changed: 219 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,224 @@ internal partial class Interop
66
{
77
internal partial class User32
88
{
9-
public const int WTS_CONSOLE_CONNECT = 0x1;
10-
public const int WTS_CONSOLE_DISCONNECT = 0x2;
11-
public const int WTS_REMOTE_CONNECT = 0x3;
12-
public const int WTS_REMOTE_DISCONNECT = 0x4;
13-
public const int WTS_SESSION_LOGON = 0x5;
14-
public const int WTS_SESSION_LOGOFF = 0x6;
15-
public const int WTS_SESSION_LOCK = 0x7;
16-
public const int WTS_SESSION_UNLOCK = 0x8;
17-
public const int WTS_SESSION_REMOTE_CONTROL = 0x9;
9+
public const int COLOR_WINDOW = 5;
10+
11+
public const int CTRL_LOGOFF_EVENT = 5;
12+
public const int CTRL_SHUTDOWN_EVENT = 6;
13+
14+
public const int ENDSESSION_CLOSEAPP = 0x00000001;
15+
public const int ENDSESSION_CRITICAL = 0x40000000;
16+
public const int ENDSESSION_LOGOFF = unchecked((int)0x80000000);
17+
18+
public const int GCL_WNDPROC = (-24);
19+
public const int GWL_WNDPROC = (-4);
20+
21+
public const int MWMO_INPUTAVAILABLE = 0x0004;
22+
23+
public const int PBT_APMQUERYSUSPEND = 0x0000;
24+
public const int PBT_APMQUERYSTANDBY = 0x0001;
25+
public const int PBT_APMQUERYSUSPENDFAILED = 0x0002;
26+
public const int PBT_APMQUERYSTANDBYFAILED = 0x0003;
27+
public const int PBT_APMSUSPEND = 0x0004;
28+
public const int PBT_APMSTANDBY = 0x0005;
29+
public const int PBT_APMRESUMECRITICAL = 0x0006;
30+
public const int PBT_APMRESUMESUSPEND = 0x0007;
31+
public const int PBT_APMRESUMESTANDBY = 0x0008;
32+
public const int PBT_APMBATTERYLOW = 0x0009;
33+
public const int PBT_APMPOWERSTATUSCHANGE = 0x000A;
34+
public const int PBT_APMOEMEVENT = 0x000B;
35+
36+
public const int PM_REMOVE = 0x0001;
37+
38+
public const int QS_KEY = 0x0001,
39+
QS_MOUSEMOVE = 0x0002,
40+
QS_MOUSEBUTTON = 0x0004,
41+
QS_POSTMESSAGE = 0x0008,
42+
QS_TIMER = 0x0010,
43+
QS_PAINT = 0x0020,
44+
QS_SENDMESSAGE = 0x0040,
45+
QS_HOTKEY = 0x0080,
46+
QS_ALLPOSTMESSAGE = 0x0100,
47+
QS_MOUSE = QS_MOUSEMOVE | QS_MOUSEBUTTON,
48+
QS_INPUT = QS_MOUSE | QS_KEY,
49+
QS_ALLEVENTS = QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY,
50+
QS_ALLINPUT = QS_INPUT | QS_POSTMESSAGE | QS_TIMER | QS_PAINT | QS_HOTKEY | QS_SENDMESSAGE;
51+
52+
public const int SPI_GETBEEP = 1;
53+
public const int SPI_SETBEEP = 2;
54+
public const int SPI_GETMOUSE = 3;
55+
public const int SPI_SETMOUSE = 4;
56+
public const int SPI_GETBORDER = 5;
57+
public const int SPI_SETBORDER = 6;
58+
public const int SPI_GETKEYBOARDSPEED = 10;
59+
public const int SPI_SETKEYBOARDSPEED = 11;
60+
public const int SPI_LANGDRIVER = 12;
61+
public const int SPI_ICONHORIZONTALSPACING = 13;
62+
public const int SPI_GETSCREENSAVETIMEOUT = 14;
63+
public const int SPI_SETSCREENSAVETIMEOUT = 15;
64+
public const int SPI_GETSCREENSAVEACTIVE = 16;
65+
public const int SPI_SETSCREENSAVEACTIVE = 17;
66+
public const int SPI_GETGRIDGRANULARITY = 18;
67+
public const int SPI_SETGRIDGRANULARITY = 19;
68+
public const int SPI_SETDESKWALLPAPER = 20;
69+
public const int SPI_SETDESKPATTERN = 21;
70+
public const int SPI_GETKEYBOARDDELAY = 22;
71+
public const int SPI_SETKEYBOARDDELAY = 23;
72+
public const int SPI_ICONVERTICALSPACING = 24;
73+
public const int SPI_GETICONTITLEWRAP = 25;
74+
public const int SPI_SETICONTITLEWRAP = 26;
75+
public const int SPI_GETMENUDROPALIGNMENT = 27;
76+
public const int SPI_SETMENUDROPALIGNMENT = 28;
77+
public const int SPI_SETDOUBLECLKWIDTH = 29;
78+
public const int SPI_SETDOUBLECLKHEIGHT = 30;
79+
public const int SPI_GETICONTITLELOGFONT = 31;
80+
public const int SPI_SETDOUBLECLICKTIME = 32;
81+
public const int SPI_SETMOUSEBUTTONSWAP = 33;
82+
public const int SPI_SETICONTITLELOGFONT = 34;
83+
public const int SPI_GETFASTTASKSWITCH = 35;
84+
public const int SPI_SETFASTTASKSWITCH = 36;
85+
public const int SPI_SETDRAGFULLWINDOWS = 37;
86+
public const int SPI_GETDRAGFULLWINDOWS = 38;
87+
public const int SPI_GETNONCLIENTMETRICS = 41;
88+
public const int SPI_SETNONCLIENTMETRICS = 42;
89+
public const int SPI_GETMINIMIZEDMETRICS = 43;
90+
public const int SPI_SETMINIMIZEDMETRICS = 44;
91+
public const int SPI_GETICONMETRICS = 45;
92+
public const int SPI_SETICONMETRICS = 46;
93+
public const int SPI_SETWORKAREA = 47;
94+
public const int SPI_GETWORKAREA = 48;
95+
public const int SPI_SETPENWINDOWS = 49;
96+
public const int SPI_GETHIGHCONTRAST = 66;
97+
public const int SPI_SETHIGHCONTRAST = 67;
98+
public const int SPI_GETKEYBOARDPREF = 68;
99+
public const int SPI_SETKEYBOARDPREF = 69;
100+
public const int SPI_GETSCREENREADER = 70;
101+
public const int SPI_SETSCREENREADER = 71;
102+
public const int SPI_GETANIMATION = 72;
103+
public const int SPI_SETANIMATION = 73;
104+
public const int SPI_GETFONTSMOOTHING = 74;
105+
public const int SPI_SETFONTSMOOTHING = 75;
106+
public const int SPI_SETDRAGWIDTH = 76;
107+
public const int SPI_SETDRAGHEIGHT = 77;
108+
public const int SPI_SETHANDHELD = 78;
109+
public const int SPI_GETLOWPOWERTIMEOUT = 79;
110+
public const int SPI_GETPOWEROFFTIMEOUT = 80;
111+
public const int SPI_SETLOWPOWERTIMEOUT = 81;
112+
public const int SPI_SETPOWEROFFTIMEOUT = 82;
113+
public const int SPI_GETLOWPOWERACTIVE = 83;
114+
public const int SPI_GETPOWEROFFACTIVE = 84;
115+
public const int SPI_SETLOWPOWERACTIVE = 85;
116+
public const int SPI_SETPOWEROFFACTIVE = 86;
117+
public const int SPI_SETCURSORS = 87;
118+
public const int SPI_SETICONS = 88;
119+
public const int SPI_GETDEFAULTINPUTLANG = 89;
120+
public const int SPI_SETDEFAULTINPUTLANG = 90;
121+
public const int SPI_SETLANGTOGGLE = 91;
122+
public const int SPI_GETWINDOWSEXTENSION = 92;
123+
public const int SPI_SETMOUSETRAILS = 93;
124+
public const int SPI_GETMOUSETRAILS = 94;
125+
public const int SPI_SETSCREENSAVERRUNNING = 97;
126+
public const int SPI_SCREENSAVERRUNNING = SPI_SETSCREENSAVERRUNNING;
127+
public const int SPI_GETFILTERKEYS = 50;
128+
public const int SPI_SETFILTERKEYS = 51;
129+
public const int SPI_GETTOGGLEKEYS = 52;
130+
public const int SPI_SETTOGGLEKEYS = 53;
131+
public const int SPI_GETMOUSEKEYS = 54;
132+
public const int SPI_SETMOUSEKEYS = 55;
133+
public const int SPI_GETSHOWSOUNDS = 56;
134+
public const int SPI_SETSHOWSOUNDS = 57;
135+
public const int SPI_GETSTICKYKEYS = 58;
136+
public const int SPI_SETSTICKYKEYS = 59;
137+
public const int SPI_GETACCESSTIMEOUT = 60;
138+
public const int SPI_SETACCESSTIMEOUT = 61;
139+
public const int SPI_GETSERIALKEYS = 62;
140+
public const int SPI_SETSERIALKEYS = 63;
141+
public const int SPI_GETSOUNDSENTRY = 64;
142+
public const int SPI_SETSOUNDSENTRY = 65;
143+
public const int SPI_GETSNAPTODEFBUTTON = 95;
144+
public const int SPI_SETSNAPTODEFBUTTON = 96;
145+
public const int SPI_GETMOUSEHOVERWIDTH = 98;
146+
public const int SPI_SETMOUSEHOVERWIDTH = 99;
147+
public const int SPI_GETMOUSEHOVERHEIGHT = 100;
148+
public const int SPI_SETMOUSEHOVERHEIGHT = 101;
149+
public const int SPI_GETMOUSEHOVERTIME = 102;
150+
public const int SPI_SETMOUSEHOVERTIME = 103;
151+
public const int SPI_GETWHEELSCROLLLINES = 104;
152+
public const int SPI_SETWHEELSCROLLLINES = 105;
153+
public const int SPI_GETMENUSHOWDELAY = 106;
154+
public const int SPI_SETMENUSHOWDELAY = 107;
155+
public const int SPI_GETSHOWIMEUI = 110;
156+
public const int SPI_SETSHOWIMEUI = 111;
157+
public const int SPI_GETMOUSESPEED = 112;
158+
public const int SPI_SETMOUSESPEED = 113;
159+
public const int SPI_GETSCREENSAVERRUNNING = 114;
160+
public const int SPI_GETDESKWALLPAPER = 115;
161+
public const int SPI_GETACTIVEWINDOWTRACKING = 0x1000;
162+
public const int SPI_SETACTIVEWINDOWTRACKING = 0x1001;
163+
public const int SPI_GETMENUANIMATION = 0x1002;
164+
public const int SPI_SETMENUANIMATION = 0x1003;
165+
public const int SPI_GETCOMBOBOXANIMATION = 0x1004;
166+
public const int SPI_SETCOMBOBOXANIMATION = 0x1005;
167+
public const int SPI_GETLISTBOXSMOOTHSCROLLING = 0x1006;
168+
public const int SPI_SETLISTBOXSMOOTHSCROLLING = 0x1007;
169+
public const int SPI_GETGRADIENTCAPTIONS = 0x1008;
170+
public const int SPI_SETGRADIENTCAPTIONS = 0x1009;
171+
public const int SPI_GETKEYBOARDCUES = 0x100A;
172+
public const int SPI_SETKEYBOARDCUES = 0x100B;
173+
public const int SPI_GETMENUUNDERLINES = SPI_GETKEYBOARDCUES;
174+
public const int SPI_SETMENUUNDERLINES = SPI_SETKEYBOARDCUES;
175+
public const int SPI_GETACTIVEWNDTRKZORDER = 0x100C;
176+
public const int SPI_SETACTIVEWNDTRKZORDER = 0x100D;
177+
public const int SPI_GETHOTTRACKING = 0x100E;
178+
public const int SPI_SETHOTTRACKING = 0x100F;
179+
public const int SPI_GETMENUFADE = 0x1012;
180+
public const int SPI_SETMENUFADE = 0x1013;
181+
public const int SPI_GETSELECTIONFADE = 0x1014;
182+
public const int SPI_SETSELECTIONFADE = 0x1015;
183+
public const int SPI_GETTOOLTIPANIMATION = 0x1016;
184+
public const int SPI_SETTOOLTIPANIMATION = 0x1017;
185+
public const int SPI_GETTOOLTIPFADE = 0x1018;
186+
public const int SPI_SETTOOLTIPFADE = 0x1019;
187+
public const int SPI_GETCURSORSHADOW = 0x101A;
188+
public const int SPI_SETCURSORSHADOW = 0x101B;
189+
public const int SPI_GETUIEFFECTS = 0x103E;
190+
public const int SPI_SETUIEFFECTS = 0x103F;
191+
public const int SPI_GETFOREGROUNDLOCKTIMEOUT = 0x2000;
192+
public const int SPI_SETFOREGROUNDLOCKTIMEOUT = 0x2001;
193+
public const int SPI_GETACTIVEWNDTRKTIMEOUT = 0x2002;
194+
public const int SPI_SETACTIVEWNDTRKTIMEOUT = 0x2003;
195+
public const int SPI_GETFOREGROUNDFLASHCOUNT = 0x2004;
196+
public const int SPI_SETFOREGROUNDFLASHCOUNT = 0x2005;
197+
public const int SPI_GETCARETWIDTH = 0x2006;
198+
public const int SPI_SETCARETWIDTH = 0x2007;
199+
200+
public const int WAIT_TIMEOUT = 0x00000102;
201+
202+
public const int WM_CLOSE = 0x0010;
203+
public const int WM_QUERYENDSESSION = 0x0011;
204+
public const int WM_QUIT = 0x0012;
205+
public const int WM_SYSCOLORCHANGE = 0x0015;
206+
public const int WM_ENDSESSION = 0x0016;
207+
public const int WM_SETTINGCHANGE = 0x001A;
208+
public const int WM_FONTCHANGE = 0x001D;
209+
public const int WM_TIMECHANGE = 0x001E;
210+
public const int WM_COMPACTING = 0x0041;
211+
public const int WM_DISPLAYCHANGE = 0x007E;
212+
public const int WM_TIMER = 0x0113;
213+
public const int WM_POWERBROADCAST = 0x0218;
214+
public const int WM_WTSSESSION_CHANGE = 0x02B1;
215+
public const int WM_PALETTECHANGED = 0x0311;
216+
public const int WM_THEMECHANGED = 0x031A;
217+
public const int WM_USER = 0x0400;
218+
public const int WM_CREATETIMER = WM_USER + 1;
219+
public const int WM_KILLTIMER = WM_USER + 2;
220+
public const int WM_REFLECT = WM_USER + 0x1C00;
221+
222+
public const int WS_POPUP = unchecked((int)0x80000000);
223+
224+
public const int WSF_VISIBLE = 0x0001;
225+
226+
public const int UOI_FLAGS = 1;
227+
18228
}
19229
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class User32
11+
{
12+
[DllImport(Libraries.User32, CharSet=CharSet.Auto, SetLastError=true, BestFitMapping=true)]
13+
public static extern IntPtr CreateWindowEx(int exStyle, string lpszClassName, string lpszWindowName, int style, int x, int y, int width,
14+
int height, IntPtr hWndParent, IntPtr hMenu, IntPtr hInst, IntPtr pvParam);
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class User32
11+
{
12+
[DllImport(Libraries.User32, CharSet = CharSet.Auto)]
13+
public static extern IntPtr DefWindowProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class User32
11+
{
12+
[DllImport(Libraries.User32, CharSet=CharSet.Auto)]
13+
public static extern bool DestroyWindow(IntPtr hWnd);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class User32
11+
{
12+
[DllImport(Libraries.User32, CharSet = CharSet.Auto)]
13+
public static extern int DispatchMessage([In] ref MSG msg);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class User32
11+
{
12+
[DllImport(Libraries.User32, CharSet=CharSet.Auto, BestFitMapping=false)]
13+
public static extern bool GetClassInfo(IntPtr hInst, string lpszClass, [In, Out] WNDCLASS_I wc);
14+
}
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
internal partial class Interop
9+
{
10+
internal partial class User32
11+
{
12+
[DllImport(Libraries.User32, ExactSpelling=true)]
13+
internal static extern IntPtr GetProcessWindowStation();
14+
}
15+
}

0 commit comments

Comments
 (0)