VC创建定时关闭的MessageBo.doc

上传人:自*** 文档编号:126216240 上传时间:2020-03-23 格式:DOC 页数:11 大小:95.50KB
返回 下载 相关 举报
VC创建定时关闭的MessageBo.doc_第1页
第1页 / 共11页
VC创建定时关闭的MessageBo.doc_第2页
第2页 / 共11页
VC创建定时关闭的MessageBo.doc_第3页
第3页 / 共11页
VC创建定时关闭的MessageBo.doc_第4页
第4页 / 共11页
VC创建定时关闭的MessageBo.doc_第5页
第5页 / 共11页
点击查看更多>>
资源描述

《VC创建定时关闭的MessageBo.doc》由会员分享,可在线阅读,更多相关《VC创建定时关闭的MessageBo.doc(11页珍藏版)》请在金锄头文库上搜索。

1、1、第一种方法:用微软提供的官方文档From : http:/ 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

2、. 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 tim

3、er 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. view plaincopy to clipboardprint?1. /* 2. THISCODEANDINFORMATION

4、ISPROVIDEDASISWITHOUTWARRANTYOF 3. ANYKIND,EITHEREXPRESSEDORIMPLIED,INCLUDINGBUTNOTLIMITEDTO 4. THEIMPLIEDWARRANTIESOFMERCHANTABILITYAND/ORFITNESSFORA 5. PARTICULARPURPOSE. 6. 7. Copyright1998MicrosoftCorporation.AllRightsReserved. 8. */9. 10. /* 11. * 12. *MsgBox.c 13. * 14. *Abstract: 15. * 16. *S

5、ampleprogramtodemonstratehowaprogramcandisplaya 17. *timedmessagebox. 18. * 19. */20. 21. #defineSTRICT 22. #include 23. 24. /* 25. * 26. *Overview 27. * 28. *Thekeytocreatingatimedmessageboxisexitingthedialog 29. *boxmessageloopinternaltothemessagebox.Becausethe 30. *messageloopforamessageboxispart

6、ofUSER,youcannot 31. *modifythemessageloopwithoutusinghooksandothersuchmethods. 32. * 33. * 34. *However,allmessageloopsexitwhentheyreceivea 35. *WM_QUITmessage.Additionally,ifanestedmessageloop 36. *receivesaWM_QUITmessage,thenestedmessageloopmustbreak 37. *theloopandthenre-postthequitmessagesothat

7、thenext 38. *outerlayercanprocessit. 39. * 40. *Therefore,youcanmakethenestedmessageloopexitby 41. *callingthePostQuitMessagefunction.Thenestedmessageloopwill 42. *cleanupandpostanewquitmessage.WhentheMessageBox 43. *returns,youpeektoseeifthereisaquitmessage.Ifso, 44. *itmeansthatthemessageloopwasab

8、normallyterminated. 45. *YoualsoconsumetheWM_QUITmessageinsteadofre-postingit 46. *sothattheapplicationcontinuestorun. 47. * 48. *Essentially,youhavetrickedthenestedmessageloopinto 49. *determiningthattheapplicationisterminating.Whenthequitmessage 50. *returns,youconsumethequitmessage.Thismethodeffe

9、ctivelycancels 51. *thefakequitmessagethatyougenerated. 52. * 53. */54. 55. /* 56. * 57. *Globalvariables 58. * 59. */60. 61. HWNDg_hwndTimedOwner; 62. BOOLg_bTimedOut; 63. 64. /* 65. * 66. *MessageBoxTimer 67. * 68. *Thetimercallbackfunctionthatpoststhefakequitmessage. 69. *Thisfunctioncausesthemes

10、sageboxtoexitbecausethemessagebox 70. *hasdeterminedthattheapplicationisexiting. 71. * 72. */73. voidCALLBACKMessageBoxTimer(HWNDhwnd, 74. UINTuiMsg, 75. UINTidEvent, 76. DWORDdwTime) 77. 78. g_bTimedOut=TRUE; 79. if(g_hwndTimedOwner) 80. EnableWindow(g_hwndTimedOwner,TRUE); 81. PostQuitMessage(0); 82. 83. 84. /* 85. * 86. *TimedMessageBox 87. * 88. *ThesameasthestandardMessageBox,exceptthatTimedMessageBox 89. *alsoacceptsatimeout.Iftheuserdoesnotrespondwithinthe 90. *specifiedtimeout,thevalue0isreturnedinsteadofoneofthe 91. *ID

展开阅读全文
相关资源
相关搜索

当前位置:首页 > IT计算机/网络 > 其它相关文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号