using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; namespace WindowsApplication1
{
public partial class AutoDeleteMessageBox : Form
{
[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; public AutoDeleteMessageBox()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
StartKiller();
MessageBox.Show("3秒钟后自动关闭MessageBox窗口", "MessageBox");
} private void StartKiller()
{
Timer timer = new Timer();
timer.Interval = ; //3秒启动
timer.Tick += new EventHandler(Timer_Tick);
timer.Start();
} private void Timer_Tick(object sender, EventArgs e)
{
KillMessageBox();
//停止Timer
((Timer)sender).Stop();
} private void KillMessageBox()
{
//按照MessageBox的标题,找到MessageBox的窗口
IntPtr ptr = FindWindow(null, "MessageBox");
if (ptr != IntPtr.Zero)
{
//找到则关闭MessageBox窗口
PostMessage(ptr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
}
}
}
}

最新文章

  1. 《Linux内核分析》之第三章读书笔记
  2. Unity(64bit)5.1 打开无故出现框框,纹理不见了
  3. Flipping elements with WPF
  4. truncate/drop表非常慢,怎么办?用硬链接,极速体验
  5. drupal 2016-11-3
  6. activiti自定义流程之自定义表单(三):表单列表及预览和删除
  7. 金融系列14《QPBOC交易流程》
  8. 引擎设计跟踪(九.14.2h) 开发计划
  9. BLOCK专题
  10. 微软Hololens学院教程-Hologram 230-空间场景建模(Spatial mapping )【微软教程已经更新,本文是老版本】
  11. placeholder
  12. OpenGL判断一个点是否可见
  13. python装饰器大详解
  14. vue elementUI之Form表单 验证
  15. NSUserDefaults standardUserDefaults使用注意事项
  16. redis学习笔记01 — 基本介绍、安装配置及常用命令
  17. logistics回归简单应用(二)
  18. vim编辑
  19. IDEA 实用功能Auto Import:自动优化导包(自动删除、导入包)
  20. 【Linux】shell学习之sed

热门文章

  1. shell学习四十八天----文件校验和匹配
  2. jmeter 发送http请求,并把获取到的请求的订单信息保存到文件中
  3. Mybatis(四):MyBatis核心组件介绍原理解析和源码解读
  4. 处理“位域”枚举类型变量的几个例子
  5. CentOS使用EPEL YUM源
  6. NGUI下拉菜单学习UIPopupList
  7. mysql部分学习心得(入门级别)
  8. RotateWorldTest对层动作
  9. python(21)实现多进程(1)
  10. Java – Convert IP address to Decimal Number