annotate ServerMonitor/Win32Helpers.cs @ 17:68d7834dc28e

More comments.
author Brad Greco <brad@bgreco.net>
date Sat, 25 May 2019 15:14:26 -0400
parents 052aa62cb42a
children 7645122aa7a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
1 using System;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
2 using System.Runtime.InteropServices;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.Windows.Forms;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 namespace ServerMonitorApp
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 {
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
7 /// <summary>Methods for interacting with the Win32 API.</summary>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8 class Win32Helpers
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 [DllImport("user32.dll")]
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 [return: MarshalAs(UnmanagedType.Bool)]
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 [StructLayout(LayoutKind.Sequential)]
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 public struct FLASHWINFO
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
16 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
17 public UInt32 cbSize;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 public IntPtr hwnd;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19 public UInt32 dwFlags;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 public UInt32 uCount;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 public UInt32 dwTimeout;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
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
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
31 public enum FlashWindowFlags : uint
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
32 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
33 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 /// Stop flashing. The system restores the window to its original state.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
36 FLASHW_STOP = 0,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
37
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
38 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
39 /// Flash the window caption
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 FLASHW_CAPTION = 1,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
42
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
43 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
44 /// Flash the taskbar button.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 FLASHW_TRAY = 2,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
48 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
49 /// Flash both the window caption and taskbar button.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
51 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
52 FLASHW_ALL = 3,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
54 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
55 /// Flash continuously, until the FLASHW_STOP flag is set.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 FLASHW_TIMER = 4,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
59 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
60 /// Flash continuously until the window comes to the foreground.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 FLASHW_TIMERNOFG = 12
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
65 /// <summary>Flashes a window icon in the taskbar.</summary>
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
66 /// <param name="form">The form to flash.</param>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
67 public static bool FlashWindowEx(Form form)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
68 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
69 IntPtr hWnd = form.Handle;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
70 FLASHWINFO fInfo = new FLASHWINFO();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
71
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
72 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 fInfo.hwnd = hWnd;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
75 fInfo.uCount = 10;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
76 fInfo.dwTimeout = 0;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
77
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
78 return FlashWindowEx(ref fInfo);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
79 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
80
17
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
81 /// <summary>Stops flashing a window icon in the taskbar.</summary>
68d7834dc28e More comments.
Brad Greco <brad@bgreco.net>
parents: 8
diff changeset
82 /// <param name="form">The form to stop flashing.</param>
4
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
83 public static bool StopFlashWindowEx(Form form)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
84 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
85 IntPtr hWnd = form.Handle;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
86 FLASHWINFO fInfo = new FLASHWINFO();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
87
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
88 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
89 fInfo.hwnd = hWnd;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
90 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
91 fInfo.dwTimeout = 0;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
92
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
93 return FlashWindowEx(ref fInfo);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
94 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
95 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
96 }