Mercurial > servermonitor
annotate ServerMonitor/Win32Helpers.cs @ 40:c4fc74593a78 default tip
Mono fix
author | Brad Greco <brad@bgreco.net> |
---|---|
date | Sat, 13 Jun 2020 13:28:20 -0400 |
parents | 7645122aa7a9 |
children |
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; |
39 | 25 |
26 #if __MonoCS__ | |
27 public static readonly int WM_SHOWMONITOR = -12345; | |
28 #else | |
29 public static readonly int WM_SHOWMONITOR = RegisterWindowMessage("WM_SHOWMONITOR"); | |
30 #endif | |
31 | |
8
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
32 [DllImport("user32")] |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
33 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
|
34 [DllImport("user32")] |
052aa62cb42a
Single instance. Add autorun option. Add icons. General enhancements.
Brad Greco <brad@bgreco.net>
parents:
4
diff
changeset
|
35 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
|
36 |
4 | 37 public enum FlashWindowFlags : uint |
38 { | |
39 /// <summary> | |
40 /// Stop flashing. The system restores the window to its original state. | |
39 | 41 /// </summary> |
4 | 42 FLASHW_STOP = 0, |
43 | |
44 /// <summary> | |
45 /// Flash the window caption | |
46 /// </summary> | |
47 FLASHW_CAPTION = 1, | |
48 | |
49 /// <summary> | |
50 /// Flash the taskbar button. | |
51 /// </summary> | |
52 FLASHW_TRAY = 2, | |
53 | |
54 /// <summary> | |
55 /// Flash both the window caption and taskbar button. | |
56 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. | |
57 /// </summary> | |
58 FLASHW_ALL = 3, | |
59 | |
60 /// <summary> | |
61 /// Flash continuously, until the FLASHW_STOP flag is set. | |
62 /// </summary> | |
63 FLASHW_TIMER = 4, | |
64 | |
65 /// <summary> | |
66 /// Flash continuously until the window comes to the foreground. | |
67 /// </summary> | |
68 FLASHW_TIMERNOFG = 12 | |
69 } | |
70 | |
17 | 71 /// <summary>Flashes a window icon in the taskbar.</summary> |
72 /// <param name="form">The form to flash.</param> | |
4 | 73 public static bool FlashWindowEx(Form form) |
74 { | |
39 | 75 if (Helpers.IsMono()) { |
76 return false; | |
77 } | |
78 | |
4 | 79 IntPtr hWnd = form.Handle; |
80 FLASHWINFO fInfo = new FLASHWINFO(); | |
81 | |
82 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); | |
83 fInfo.hwnd = hWnd; | |
84 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY; | |
85 fInfo.uCount = 10; | |
86 fInfo.dwTimeout = 0; | |
87 | |
88 return FlashWindowEx(ref fInfo); | |
89 } | |
90 | |
17 | 91 /// <summary>Stops flashing a window icon in the taskbar.</summary> |
92 /// <param name="form">The form to stop flashing.</param> | |
4 | 93 public static bool StopFlashWindowEx(Form form) |
94 { | |
39 | 95 if (Helpers.IsMono()) { |
96 return false; | |
97 } | |
98 | |
4 | 99 IntPtr hWnd = form.Handle; |
100 FLASHWINFO fInfo = new FLASHWINFO(); | |
101 | |
102 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); | |
103 fInfo.hwnd = hWnd; | |
104 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP; | |
105 fInfo.dwTimeout = 0; | |
106 | |
107 return FlashWindowEx(ref fInfo); | |
108 } | |
109 } | |
110 } |