程序启动后显示A窗口,A窗口有60秒倒计时,60秒会后跳转到B窗口
A窗口启动后,会启动一个新的c线程,来执行刷卡操作,30秒后c线程结束并弹出messagebox
现在假如不关闭messagebox,倒计时60秒完成后跳转到B窗口,但是之前那个messagebox并没有关闭
这种情况怎么样处理?
A窗口启动后,会启动一个新的c线程,来执行刷卡操作,30秒后c线程结束并弹出messagebox
现在假如不关闭messagebox,倒计时60秒完成后跳转到B窗口,但是之前那个messagebox并没有关闭
这种情况怎么样处理?
解决方案
40
[DllImport(“user32.dll”, EntryPoint = “FindWindow”, CharSet = CharSet.Auto)]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport(“user32.dll”, CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public const int WM_CLOSE = 0x10;
MessageBox.Show(“text”, “caption”);
//按照MessageBox的标题,找到MessageBox的窗口
IntPtr ptr = FindWindow(null, “caption”);
if (ptr != IntPtr.Zero)
{
//找到则关闭MessageBox窗口
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport(“user32.dll”, CharSet = CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public const int WM_CLOSE = 0x10;
MessageBox.Show(“text”, “caption”);
//按照MessageBox的标题,找到MessageBox的窗口
IntPtr ptr = FindWindow(null, “caption”);
if (ptr != IntPtr.Zero)
{
//找到则关闭MessageBox窗口
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}