Mercurial > servermonitor
annotate ServerMonitor/Win32Helpers.cs @ 14:2db36ab759de
Add comments.
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Mon, 22 Apr 2019 21:10:42 -0400 |
parents | 052aa62cb42a |
children | 68d7834dc28e |
rev | line source |
---|---|
4 | 1 using System; |
2 using System.Collections.Generic; | |
3 using System.Linq; | |
4 using System.Runtime.InteropServices; | |
5 using System.Text; | |
6 using System.Threading.Tasks; | |
7 using System.Windows.Forms; | |
8 | |
9 namespace ServerMonitorApp | |
10 { | |
11 class Win32Helpers | |
12 { | |
13 [DllImport("user32.dll")] | |
14 [return: MarshalAs(UnmanagedType.Bool)] | |
15 static extern bool FlashWindowEx(ref FLASHWINFO pwfi); | |
16 | |
17 [StructLayout(LayoutKind.Sequential)] | |
18 public struct FLASHWINFO | |
19 { | |
20 public UInt32 cbSize; | |
21 public IntPtr hwnd; | |
22 public UInt32 dwFlags; | |
23 public UInt32 uCount; | |
24 public UInt32 dwTimeout; | |
25 } | |
26 | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
27 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
|
28 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
|
29 [DllImport("user32")] |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
30 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
|
31 [DllImport("user32")] |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
32 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
|
33 |
4 | 34 public enum FlashWindowFlags : uint |
35 { | |
36 /// <summary> | |
37 /// Stop flashing. The system restores the window to its original state. | |
38 /// </summary> | |
39 FLASHW_STOP = 0, | |
40 | |
41 /// <summary> | |
42 /// Flash the window caption | |
43 /// </summary> | |
44 FLASHW_CAPTION = 1, | |
45 | |
46 /// <summary> | |
47 /// Flash the taskbar button. | |
48 /// </summary> | |
49 FLASHW_TRAY = 2, | |
50 | |
51 /// <summary> | |
52 /// Flash both the window caption and taskbar button. | |
53 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. | |
54 /// </summary> | |
55 FLASHW_ALL = 3, | |
56 | |
57 /// <summary> | |
58 /// Flash continuously, until the FLASHW_STOP flag is set. | |
59 /// </summary> | |
60 FLASHW_TIMER = 4, | |
61 | |
62 /// <summary> | |
63 /// Flash continuously until the window comes to the foreground. | |
64 /// </summary> | |
65 FLASHW_TIMERNOFG = 12 | |
66 } | |
67 | |
68 public static bool FlashWindowEx(Form form) | |
69 { | |
70 IntPtr hWnd = form.Handle; | |
71 FLASHWINFO fInfo = new FLASHWINFO(); | |
72 | |
73 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); | |
74 fInfo.hwnd = hWnd; | |
75 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY; | |
76 fInfo.uCount = 10; | |
77 fInfo.dwTimeout = 0; | |
78 | |
79 return FlashWindowEx(ref fInfo); | |
80 } | |
81 | |
82 public static bool StopFlashWindowEx(Form form) | |
83 { | |
84 IntPtr hWnd = form.Handle; | |
85 FLASHWINFO fInfo = new FLASHWINFO(); | |
86 | |
87 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); | |
88 fInfo.hwnd = hWnd; | |
89 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP; | |
90 fInfo.dwTimeout = 0; | |
91 | |
92 return FlashWindowEx(ref fInfo); | |
93 } | |
94 } | |
95 } |