-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMessageBoxAutoClosing.cs
162 lines (144 loc) · 6.18 KB
/
MessageBoxAutoClosing.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Creado por SharpDevelop.
* Usuario: GNR092
* Fecha: 06/02/2017
* Hora: 08:04 p.m.
*
* Para cambiar esta plantilla use Herramientas | Opciones | Codificación | Editar Encabezados Estándar
*/
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace SecureGameGuard
{
public class MessageBoxAutoClosing
{
System.Threading.Timer _timeoutTimer;
string _caption;
MessageBoxIcon icons;
MessageBoxButtons Buttoms;
#region ctor
public MessageBoxAutoClosing(string text, int timeout)
{
_caption = "inf";
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text);
}
public MessageBoxAutoClosing(string text, string caption, int timeout)
{
_caption = caption;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption);
}
public MessageBoxAutoClosing(string text, string caption, int timeout, MessageBoxAutoClosingButtoms buttom)
{
_caption = caption;
icons = (MessageBoxIcon)icon;
Buttoms = (MessageBoxButtons)buttom;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption, Buttoms);
}
public MessageBoxAutoClosing(string text, string caption, int timeout, MessageBoxAutoClosingButtoms buttom , MessageBoxAutoClosingIcon icon)
{
_caption = caption;
icons = (MessageBoxIcon)icon;
Buttoms = (MessageBoxButtons)buttom;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption, Buttoms, icons);
}
public MessageBoxAutoClosing(string text, string caption, int timeout, MessageBoxAutoClosingIcon icon)
{
_caption = caption;
icons = (MessageBoxIcon)icon;
_timeoutTimer = new System.Threading.Timer(OnTimerElapsed,
null, timeout, System.Threading.Timeout.Infinite);
MessageBox.Show(text, caption, MessageBoxButtons.OK, icons);
}
#endregion
#region Show
public static void Show(object text, int timeout)
{
new MessageBoxAutoClosing(text.ToString(), timeout);
}
public static void Show(string text, int timeout)
{
new MessageBoxAutoClosing(text, timeout);
}
public static void Show(object text, string caption, int timeout)
{
new MessageBoxAutoClosing(text.ToString(), caption, timeout);
}
public static void Show(string text, string caption, int timeout)
{
new MessageBoxAutoClosing(text, caption, timeout);
}
public static void Show(string text, string caption, int timeout,MessageBoxAutoClosingButtoms buttom)
{
new MessageBoxAutoClosing(text, caption, timeout,buttom);
}
public static void Show(object text, string caption, int timeout, MessageBoxAutoClosingButtoms buttom)
{
new MessageBoxAutoClosing(text.ToString(), caption, timeout, buttom);
}
public static void Show(string text, string caption, int timeout, MessageBoxAutoClosingButtoms buttom, MessageBoxAutoClosingIcon icon)
{
new MessageBoxAutoClosing(text, caption, timeout, buttom,icon);
}
public static void Show(object text, string caption, int timeout, MessageBoxAutoClosingButtoms buttom, MessageBoxAutoClosingIcon icon)
{
new MessageBoxAutoClosing(text.ToString(), caption, timeout, buttom, icon);
}
public static void Show(string text, string caption, int timeout,MessageBoxAutoClosingIcon icon)
{
new MessageBoxAutoClosing(text, caption, timeout, icon);
}
public static void Show(object text, string caption, int timeout, MessageBoxAutoClosingIcon icon)
{
new MessageBoxAutoClosing(text.ToString(), caption, timeout, icon);
}
#region formats
public static void Show(string format, int timeout, params object[] args)
{
Show(string.Format(format, args), timeout);
}
public static void Show(string format, string caption, int timeout, params object[] args)
{
Show(string.Format(format, args), caption, timeout);
}
public static void Show(string format, string caption, int timeout, MessageBoxAutoClosingIcon icon, params object[] args)
{
Show(string.Format(format, args), caption, timeout, icon);
}
public static void Show(string format, string caption, int timeout, MessageBoxAutoClosingButtoms buttom, params object[] args)
{
Show(string.Format(format, args), caption, timeout, buttom);
}
public static void Show(string format, string caption, int timeout, MessageBoxAutoClosingButtoms buttom, MessageBoxAutoClosingIcon icon, params object[] args)
{
Show(string.Format(format, args), caption, timeout, buttom,icon);
}
#endregion
#endregion
private void OnTimerElapsed(object state)
{
IntPtr mbWnd = FindWindow(null, _caption);
if (mbWnd != IntPtr.Zero)
SendMessage(mbWnd, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
_timeoutTimer.Dispose();
}
const int WM_CLOSE = 0x0010;
private string text;
private string caption;
private int timeout;
private MessageBoxAutoClosingIcon icon;
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
}
}