Files
01-Siyuan-MesProject/DataMirrorTools_Simulator/ModelBasic/BasicClass/AutoMessageBox.cs
2026-05-29 10:07:05 +08:00

32 lines
1.3 KiB
C#

using System;
using System.Windows.Forms;
public class AutoClosingMessageBox
{
private System.Threading.Timer _timeoutTimer;
private string _caption;
private const int WM_CLOSE = 16;
private AutoClosingMessageBox(string text, string caption, int timeout)
{
this._caption = caption;
this._timeoutTimer = new System.Threading.Timer(new System.Threading.TimerCallback(this.OnTimerElapsed), null, timeout, -1);
MessageBox.Show(text, caption);
}
public static void Show(string text, string caption, int timeout)
{
new AutoClosingMessageBox(text, caption, timeout);
}
private void OnTimerElapsed(object state)
{
IntPtr intPtr = AutoClosingMessageBox.FindWindow(null, this._caption);
if (intPtr != IntPtr.Zero)
{
AutoClosingMessageBox.SendMessage(intPtr, 16u, IntPtr.Zero, IntPtr.Zero);
}
this._timeoutTimer.Dispose();
}
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
private static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, IntPtr lParam);
}