![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Application.Run(new Form1());
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void button1_Click(object sender, System.EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
StartKiller();
MessageBox.Show("这里是MessageBox弹出的内容","MessageBox");
MessageBox.Show("这里是跟随运行的窗口","窗口");
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void StartKiller()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
Timer timer = new Timer();
timer.Interval = 10000; //10秒启动
timer.Tick += new EventHandler(Timer_Tick);
timer.Start();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void Timer_Tick(object sender, EventArgs e)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
KillMessageBox();
//停止计时器
((Timer)sender).Stop();
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private void KillMessageBox()
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
//查找MessageBox的弹出窗口,注意对应标题
IntPtr ptr = FindWindow(null,"MessageBox");
if(ptr != IntPtr.Zero)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
//查找到窗口则关闭
PostMessage(ptr,WM_CLOSE,IntPtr.Zero,IntPtr.Zero);
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet=CharSet.Auto)]
private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int PostMessage(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public const int WM_CLOSE = 0x10;
}
}
posted @
2008-09-02 16:30
赖文华.NET
阅读(
756)
评论()
编辑
收藏
举报