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
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.Collections.Generic;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
3 using System.Linq;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
4 using System.Runtime.InteropServices;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
5 using System.Text;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
6 using System.Threading.Tasks;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
7 using System.Windows.Forms;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
8
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
9 namespace ServerMonitorApp
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
10 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
11 class Win32Helpers
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
12 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
13 [DllImport("user32.dll")]
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
14 [return: MarshalAs(UnmanagedType.Bool)]
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
15 static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
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 [StructLayout(LayoutKind.Sequential)]
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
18 public struct FLASHWINFO
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
19 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
20 public UInt32 cbSize;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
21 public IntPtr hwnd;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
22 public UInt32 dwFlags;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
23 public UInt32 uCount;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
24 public UInt32 dwTimeout;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
25 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
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
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
34 public enum FlashWindowFlags : uint
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
35 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
36 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
37 /// Stop flashing. The system restores the window to its original state.
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 FLASHW_STOP = 0,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
40
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
41 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
42 /// Flash the window caption
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 FLASHW_CAPTION = 1,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
45
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
46 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
47 /// Flash the taskbar button.
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 FLASHW_TRAY = 2,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
50
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 /// Flash both the window caption and taskbar button.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
53 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
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 FLASHW_ALL = 3,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
56
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
57 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
58 /// Flash continuously, until the FLASHW_STOP flag is set.
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 FLASHW_TIMER = 4,
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
61
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
62 /// <summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
63 /// Flash continuously until the window comes to the foreground.
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
64 /// </summary>
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
65 FLASHW_TIMERNOFG = 12
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
66 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
67
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
68 public static bool FlashWindowEx(Form form)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
69 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
70 IntPtr hWnd = form.Handle;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
71 FLASHWINFO fInfo = new FLASHWINFO();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
72
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
73 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
74 fInfo.hwnd = hWnd;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
75 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
76 fInfo.uCount = 10;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
77 fInfo.dwTimeout = 0;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
78
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
79 return FlashWindowEx(ref fInfo);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
80 }
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
81
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
82 public static bool StopFlashWindowEx(Form form)
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
83 {
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
84 IntPtr hWnd = form.Handle;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
85 FLASHWINFO fInfo = new FLASHWINFO();
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
86
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
87 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
88 fInfo.hwnd = hWnd;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
89 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
90 fInfo.dwTimeout = 0;
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
91
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
92 return FlashWindowEx(ref fInfo);
3142e52cbe69 Lots more progress
Brad Greco <brad@bgreco.net>
parents:
diff changeset
93 }
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 }