VC创建定时关闭的MessageBox

1、第一种方法:用微软提供的官方文档

From : http://support.microsoft.com/kb/181934/en-us/

 

Generally, when you want to display a message box for a limited amount of time, you must implement a regular dialog box that closes itself after a specified amount of time. The problem with this method is that you lose the standard message box functionality that Windows provides.

The following example shows how to use the MessageBox function to create a message box that automatically closes after a specified amount of time. Note the following about the example:

  • The example uses a Windows timer that fires an event after the specified amount of time has elapsed.
  • When the timer event occurs, the PostQuitMessage API is used to break out of the modal message loop that MessageBox uses.
  • Note The WM_QUIT message must be removed from the message queue to prevent it from being retrieved in the main message queue.

 

2、第二种方法:使用手动创建的对话框

新建一个对话框,添加一个静态文本控件(显示内容),如下图:

定时自动关闭MessageBox

 

将Static控件关联CString类型变量为m_strText、并为该对话框添加新类CMSGBox,再添加WM_TIMER消息:

PS:我觉得此处代码可以改成这样,就可以设定多个定时器(我可没测试

 

引入头文件,在主对话框中调用代码:

 

运行效果如下:

效果

 

这种山寨版的效果,确实看起来有些猥琐....

3、源码下载(SDK、MFC共两种)

     官方下载:http://download.csdn.net/source/1808835

     网盘下载:http://www.rayfile.com/files/c07e4600-ce99-11de-82ad-0014221b798a/

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

汪宁宇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值