comparison ServerMonitor/Win32Helpers.cs @ 4:3142e52cbe69

Lots more progress
author Brad Greco <brad@bgreco.net>
date Sun, 10 Feb 2019 20:51:26 -0500
parents
children 052aa62cb42a
comparison
equal deleted inserted replaced
3:96f0b028176d 4:3142e52cbe69
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
27 public enum FlashWindowFlags : uint
28 {
29 /// <summary>
30 /// Stop flashing. The system restores the window to its original state.
31 /// </summary>
32 FLASHW_STOP = 0,
33
34 /// <summary>
35 /// Flash the window caption
36 /// </summary>
37 FLASHW_CAPTION = 1,
38
39 /// <summary>
40 /// Flash the taskbar button.
41 /// </summary>
42 FLASHW_TRAY = 2,
43
44 /// <summary>
45 /// Flash both the window caption and taskbar button.
46 /// This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
47 /// </summary>
48 FLASHW_ALL = 3,
49
50 /// <summary>
51 /// Flash continuously, until the FLASHW_STOP flag is set.
52 /// </summary>
53 FLASHW_TIMER = 4,
54
55 /// <summary>
56 /// Flash continuously until the window comes to the foreground.
57 /// </summary>
58 FLASHW_TIMERNOFG = 12
59 }
60
61 public static bool FlashWindowEx(Form form)
62 {
63 IntPtr hWnd = form.Handle;
64 FLASHWINFO fInfo = new FLASHWINFO();
65
66 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
67 fInfo.hwnd = hWnd;
68 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_TRAY;
69 fInfo.uCount = 10;
70 fInfo.dwTimeout = 0;
71
72 return FlashWindowEx(ref fInfo);
73 }
74
75 public static bool StopFlashWindowEx(Form form)
76 {
77 IntPtr hWnd = form.Handle;
78 FLASHWINFO fInfo = new FLASHWINFO();
79
80 fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
81 fInfo.hwnd = hWnd;
82 fInfo.dwFlags = (uint)FlashWindowFlags.FLASHW_STOP;
83 fInfo.dwTimeout = 0;
84
85 return FlashWindowEx(ref fInfo);
86 }
87 }
88 }