Mercurial > servermonitor
annotate ServerMonitor/Win32Helpers.cs @ 35:2ffb0bda7705
Increase wait time after system resume to begin running checks to prevent false positives.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sat, 13 Jul 2019 12:18:21 -0400 |
parents | 68d7834dc28e |
children | 7645122aa7a9 |
rev | line source |
---|---|
4 | 1 using System; |
2 using System.Runtime.InteropServices; | |
3 using System.Windows.Forms; | |
4 | |
5 namespace ServerMonitorApp | |
6 { | |
17 | 7 /// <summary>Methods for interacting with the Win32 API.</summary> |
4 | 8 class Win32Helpers |
9 { | |
10 [DllImport("user32.dll")] | |
11 [return: MarshalAs(UnmanagedType.Bool)] | |
12 static extern bool FlashWindowEx(ref FLASHWINFO pwfi); | |
13 | |
14 [StructLayout(LayoutKind.Sequential)] | |
15 public struct FLASHWINFO | |
16 { | |
17 public UInt32 cbSize; | |
18 public IntPtr hwnd; | |
19 public UInt32 dwFlags; | |
20 public UInt32 uCount; | |
21 public UInt32 dwTimeout; | |
22 } | |
23 | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
24 public const int HWND_BROADCAST = 0xffff; |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
25 public static readonly int WM_SHOWMONITOR = RegisterWindowMessage("WM_SHOWMONITOR"); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
26 [DllImport("user32")] |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
27 public static extern bool PostMessage(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
28 [DllImport("user32")] |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
29 public static extern int RegisterWindowMessage(string message); |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
30 |
4 | 31 public enum FlashWindowFlags : uint |
32 { | |
33 /// <summary> | |
34 /// Stop flashing. The system restores the window to its original state. | |
35 /// </summary> | |
36 FLASHW_STOP = 0, | |
37 | |
38 /// <summary> | |
39 /// Flash the window caption | |
40 /// </summary> | |
41 FLASHW_CAPTION = 1, | |
42 | |
43 /// <summary> | |
44 /// Flash the taskbar button. | |
45 /// </summary> | |
46 FLASHW_TRAY = 2, | |
47 | |
48 /// <summary> | |
49 /// Flash both the window caption and taskbar button. | |
50 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. | |
51 /// </summary> | |
52 FLASHW_ALL = 3, | |
53 | |
54 /// <summary> | |
55 /// Flash continuously, until the FLASHW_STOP flag is set. | |
56 /// </summary> | |
57 FLASHW_TIMER = 4, | |
58 | |
59 /// <summary> | |
60 /// Flash continuously until the window comes to the foreground. | |
61 /// </summary> | |
62 FLASHW_TIMERNOFG = 12 | |
63 } | |
64 | |
17 | 65 /// <summary>Flashes a window icon in the taskbar.</summary> |
66 /// <param name="form">The form to flash.</param> | |
4 | 67 public static bool FlashWindowEx(Form form) |
68 { | |
69 IntPtr hWnd = form.Handle; | |
70 FLASHWINFO fInfo = new FLASHWINFO(); | |
71 | |
72 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); | |
73 fInfo.hwnd = hWnd; | |
74 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY; | |
75 fInfo.uCount = 10; | |
76 fInfo.dwTimeout = 0; | |
77 | |
78 return FlashWindowEx(ref fInfo); | |
79 } | |
80 | |
17 | 81 /// <summary>Stops flashing a window icon in the taskbar.</summary> |
82 /// <param name="form">The form to stop flashing.</param> | |
4 | 83 public static bool StopFlashWindowEx(Form form) |
84 { | |
85 IntPtr hWnd = form.Handle; | |
86 FLASHWINFO fInfo = new FLASHWINFO(); | |
87 | |
88 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); | |
89 fInfo.hwnd = hWnd; | |
90 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP; | |
91 fInfo.dwTimeout = 0; | |
92 | |
93 return FlashWindowEx(ref fInfo); | |
94 } | |
95 } | |
96 } |