OSDN Git Service

Final tweaks to 1.9 release
[radegast/radegast.git] / Radegast / FormFlash.cs
1 // \r
2 // Radegast Metaverse Client\r
3 // Copyright (c) 2009, Radegast Development Team\r
4 // All rights reserved.\r
5 // \r
6 // Redistribution and use in source and binary forms, with or without\r
7 // modification, are permitted provided that the following conditions are met:\r
8 // \r
9 //     * Redistributions of source code must retain the above copyright notice,\r
10 //       this list of conditions and the following disclaimer.\r
11 //     * Redistributions in binary form must reproduce the above copyright\r
12 //       notice, this list of conditions and the following disclaimer in the\r
13 //       documentation and/or other materials provided with the distribution.\r
14 //     * Neither the name of the application "Radegast", nor the names of its\r
15 //       contributors may be used to endorse or promote products derived from\r
16 //       this software without specific prior written permission.\r
17 // \r
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE\r
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\r
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER\r
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,\r
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 //\r
29 // $Id$\r
30 //\r
31 using System;\r
32 using System.Runtime.InteropServices;\r
33 using System.Windows.Forms;\r
34 \r
35 public static class FormFlash\r
36 {\r
37     [DllImport("user32.dll")]\r
38     public static extern int FlashWindowEx(ref FLASHWINFO pfwi);\r
39 \r
40     /// <summary>\r
41     /// Flashes the form's taskbar button.\r
42     /// </summary>\r
43     /// <param name="form"></param>\r
44     public static void StartFlash(Form form)\r
45     {\r
46         if (Type.GetType("Mono.Runtime") != null || form.Focused)\r
47         {\r
48             return;\r
49         }\r
50 \r
51         FLASHWINFO fw = new FLASHWINFO()\r
52         {\r
53             cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO))),\r
54             hwnd = form.Handle,\r
55             dwFlags = (Int32)(FLASHWINFOFLAGS.FLASHW_TRAY | FLASHWINFOFLAGS.FLASHW_TIMERNOFG),\r
56             uCount = 5,\r
57             dwTimeout = 0\r
58         };\r
59 \r
60         FlashWindowEx(ref fw);\r
61     }\r
62 \r
63     /// <summary>\r
64     /// Stops flashing the form's taskbar button.\r
65     /// </summary>\r
66     /// <param name="form"></param>\r
67     public static void StopFlash(Form form)\r
68     {\r
69         if (Type.GetType("Mono.Runtime") != null)\r
70         {\r
71             return;\r
72         }\r
73 \r
74         FLASHWINFO fw = new FLASHWINFO()\r
75         {\r
76             cbSize = Convert.ToUInt32(Marshal.SizeOf(typeof(FLASHWINFO))),\r
77             hwnd = form.Handle,\r
78             dwFlags = (Int32)(FLASHWINFOFLAGS.FLASHW_STOP),\r
79             uCount = 0,\r
80             dwTimeout = 0\r
81         };\r
82 \r
83         FlashWindowEx(ref fw);\r
84     }\r
85 }\r
86 \r
87 [StructLayout(LayoutKind.Sequential)]\r
88 public struct FLASHWINFO\r
89 {\r
90     public UInt32 cbSize;\r
91     public IntPtr hwnd;\r
92     public Int32 dwFlags;\r
93     public UInt32 uCount;\r
94     public Int32 dwTimeout;\r
95 }\r
96 \r
97 public enum FLASHWINFOFLAGS\r
98 {\r
99     FLASHW_STOP = 0,\r
100     FLASHW_CAPTION = 0x00000001,\r
101     FLASHW_TRAY = 0x00000002,\r
102     FLASHW_ALL = (FLASHW_CAPTION | FLASHW_TRAY),\r
103     FLASHW_TIMER = 0x00000004,\r
104     FLASHW_TIMERNOFG = 0x0000000C\r
105 }\r