未公开函数MessageBoxTimeOut 实现定时消息(ZT) MFC实现MessageBox自动消失
2014-04-16 10:45
483 查看
http://www.blogjava.net/baicker/archive/2007/07/13/130072.html
#include<windows.h> #include<tchar.h> //Functions&otherdefinitionsrequired--> typedefint(__stdcall*MSGBOXAAPI)(INHWNDhWnd, INLPCSTRlpText,INLPCSTRlpCaption, INUINTuType,INWORDwLanguageId,INDWORDdwMilliseconds); typedefint(__stdcall*MSGBOXWAPI)(INHWNDhWnd, INLPCWSTRlpText,INLPCWSTRlpCaption, INUINTuType,INWORDwLanguageId,INDWORDdwMilliseconds); intMessageBoxTimeoutA(INHWNDhWnd,INLPCSTRlpText, INLPCSTRlpCaption,INUINTuType, INWORDwLanguageId,INDWORDdwMilliseconds); intMessageBoxTimeoutW(INHWNDhWnd,INLPCWSTRlpText, INLPCWSTRlpCaption,INUINTuType, INWORDwLanguageId,INDWORDdwMilliseconds); #ifdefUNICODE #defineMessageBoxTimeoutMessageBoxTimeoutW #else #defineMessageBoxTimeoutMessageBoxTimeoutA #endif #defineMB_TIMEDOUT32000 intMessageBoxTimeoutA(HWNDhWnd,LPCSTRlpText, LPCSTRlpCaption,UINTuType,WORDwLanguageId, DWORDdwMilliseconds) { staticMSGBOXAAPIMsgBoxTOA=NULL; if(!MsgBoxTOA) { HMODULEhUser32=GetModuleHandle(_T("user32.dll")); if(hUser32) { MsgBoxTOA=(MSGBOXAAPI)GetProcAddress(hUser32, "MessageBoxTimeoutA"); //fallthroughto'if(MsgBoxTOA)...' } else { //stuffhappened,addcodetohandleithere //(possiblyjustcallMessageBox()) return0; } } if(MsgBoxTOA) { returnMsgBoxTOA(hWnd,lpText,lpCaption, uType,wLanguageId,dwMilliseconds); } return0; } intMessageBoxTimeoutW(HWNDhWnd,LPCWSTRlpText, LPCWSTRlpCaption,UINTuType,WORDwLanguageId,DWORDdwMilliseconds) { staticMSGBOXWAPIMsgBoxTOW=NULL; if(!MsgBoxTOW) { HMODULEhUser32=GetModuleHandle(_T("user32.dll")); if(hUser32) { MsgBoxTOW=(MSGBOXWAPI)GetProcAddress(hUser32, "MessageBoxTimeoutW"); //fallthroughto'if(MsgBoxTOW)...' } else { //stuffhappened,addcodetohandleithere //(possiblyjustcallMessageBox()) return0; } } if(MsgBoxTOW) { returnMsgBoxTOW(hWnd,lpText,lpCaption, uType,wLanguageId,dwMilliseconds); } return0; } //Endrequireddefinitions<-- //Callthefunctionasfollows: //Collapse //youmustloaduser32.dllbeforecallingthefunction main() { HMODULEhUser32=LoadLibrary(_T("user32.dll")); if(hUser32) { intiRet=0; UINTuiFlags=MB_OK|MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_ICONINFORMATION; iRet=MessageBoxTimeout(NULL,_T("Testatimeoutof2seconds."), _T("MessageBoxTimeoutTest"),uiFlags,0,2000); //iRetwill=1 uiFlags=MB_YESNO|MB_SETFOREGROUND|MB_SYSTEMMODAL|MB_ICONINFORMATION; iRet=MessageBoxTimeout(NULL,_T("Testatimeoutof5seconds."), _T("MessageBoxTimeoutTest"),uiFlags,0,5000); //iRetwill=MB_TIMEDOUTifnobuttonspressed,buttonvaluesotherwise //onlyunloaduser32.dllwhenyouhavenofurtherneed //fortheMessageBoxTimeoutfunction FreeLibrary(hUser32); } }
相关文章推荐
- Jquery 网站保存信息提示消息实现,提示后自动消失
- winform 实现MessageBox 定时消失
- IOS实现消息自动消失
- 可设置指定时间自动消失的 MessageBox实现
- MFC 定时触发器实现循环给指定线程进行发送消息
- Jquery 网站保存信息提示消息实现,提示后自动消失
- MFC启用WM_PAINT消息实现避免文本信息因窗口重绘而消失
- MFC中消息机制之实现多窗体信息的传输
- ios中提示信息的实现及自动消失
- Popupwin结合Timer实现定时弹出消息提示
- 使用SQL Server维护计划实现数据库定时自动备份
- MFC实现文件的自动保存
- MFC上下浮动与渐入渐出消息提示框实现
- MFC中消息映射的实现
- MFC调用mstscax.dll控件实现远程连接(添加消息回调)
- linux下如何实现mysql数据库每天自动备份定时备份
- mfc c++ navmesh自动寻路实现
- MFC的消息映射实现
- 用win32 api(非mfc)实现的一个圆形按钮以及WM_COMMAND消息
- MFC EditControl控件实现换行且滚动条自动跟随(实例)