现在的位置: 首页 > 综合 > 正文

VC创建定时关闭的MessageBox

2018年05月29日 ⁄ 综合 ⁄ 共 5879字 ⁄ 字号 评论关闭

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/

抱歉!评论已关闭.