Auto-close message box
来源:互联网 发布:淘宝怎么组装电脑 编辑:程序博客网 时间:2024/05/18 01:00
文章来源:http://www.codeproject.com/Articles/19714/Auto-close-message-box
Understanding the CMsgBox class
CMsgBox
is a class which implements auto-close functionality. This class is derived from the CWnd
class. It exposes a method called "MessageBox()
", which in turn would call CWnd::MessageBox()
to display a message box.
Getting the auto-close functionality implemented is very simple. In the CMsgBox::MessageBox()
method, we start a timer (SetTimer()
method) just before we call the CWnd::MessageBox
API. In the OnTimer
method, we try to find the message box window by using its window name (caption). Once found, we post a WM_CLOSE
message to close the message box. That's it !
void CMsgBox::MessageBox(CString sMsg, CString sCaption, UINT nSleep, UINT nFlags, bool bAutoClose){ // Save the caption, for finding this // message box window later m_Caption = sCaption; // If auto close then, start the timer. if(bAutoClose) SetTimer(100, nSleep, NULL); // Show the message box CWnd::MessageBox(sMsg, sCaption, nFlags);}void CMsgBox::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default BOOL bRetVal = false; // Find the message box window using the caption CWnd* pWnd = FindWindow(NULL, m_Caption); if(pWnd != NULL) { // Send close command to the message box window ::PostMessage(pWnd->m_hWnd, WM_CLOSE, 0, 0); } // Kill the timer KillTimer(100); CWnd::OnTimer(nIDEvent);}
Using the code
Add these two files to your project: "MsgBox.cpp" and "MsgBox.h". #include "MsgBox.h"
wherever appropriate. Create the CMsgBox
object as:
CMsgBox obj(this);
Or like this:
CMsgBox obj;obj.SetParent(this);
Use the MessageBox()
method for displaying the message box. Set the bAutoClose
parameter to false if you don't need the auto-close functionality.
obj.MessageBox("This message box will auto close in 2 seconds.", "Auto Close Msg Box", 2000, MB_OK | MB_ICONINFORMATION);
- Auto-close message box
- Close auto share
- Message-Box Styles
- allegro GUI message box实例
- Windows Phone 7 - Message Box
- Message Box (Action Sheet) General
- 消息框(Message box)
- Server side Message box in ASP.Net
- Windows Phone 7 Custom Message Box
- Using Message Box (MsgBox) in Excel VBA
- mint-ui Message-box 自定义样式
- Auto Restart application after Crash/Force Close in Android
- Auto Restart application after Crash/Force Close in Android
- Auto Complete combo Box(VB.NET Source Use API)
- Asp.net中创建Auto Complete Text Box 概述
- Auto Complete combo Box(VB.NET Source Use API)
- Auto Complete combo Box(VB.NET Source Use API)
- ExtJS 学习系列(2)---Message Box 详解 (2)
- HTTP连接出错:android.os.NetworkOnMainThreadException
- CRC详解及在LTE中的应用
- Android 手机录制wav格式音频文件实现
- ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using passwor
- xUtils 源码解析
- Auto-close message box
- Android webview使用注意
- Memcache CAS协议介绍及使用
- 欢迎使用CSDN-markdown编辑器
- iOS开发者必知工具
- Android百度地图V3.20隐藏百度图标、比例尺、缩放按钮方法
- Xcode 清理工程
- rtp h264注意点(FU-A分包方式说明)
- HTML5 canvas热点图应用