




已閱讀5頁,還剩6頁未讀, 繼續(xù)免費閱讀
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、第一種方法:用微軟提供的官方文檔From : /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. view plaincopy to clipboardprint?1. /* 2. THISCODEANDINFORMATIONISPROVIDEDASISWITHOUTWARRANTYOF 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. *Sampleprogramtodemonstratehowaprogramcandisplaya 17. *timedmessagebox. 18. * 19. */20. 21. #defineSTRICT 22. #include 23. 24. /* 25. * 26. *Overview 27. * 28. *Thekeytocreatingatimedmessageboxisexitingthedialog 29. *boxmessageloopinternaltothemessagebox.Becausethe 30. *messageloopforamessageboxispartofUSER,youcannot 31. *modifythemessageloopwithoutusinghooksandothersuchmethods. 32. * 33. * 34. *However,allmessageloopsexitwhentheyreceivea 35. *WM_QUITmessage.Additionally,ifanestedmessageloop 36. *receivesaWM_QUITmessage,thenestedmessageloopmustbreak 37. *theloopandthenre-postthequitmessagesothatthenext 38. *outerlayercanprocessit. 39. * 40. *Therefore,youcanmakethenestedmessageloopexitby 41. *callingthePostQuitMessagefunction.Thenestedmessageloopwill 42. *cleanupandpostanewquitmessage.WhentheMessageBox 43. *returns,youpeektoseeifthereisaquitmessage.Ifso, 44. *itmeansthatthemessageloopwasabnormallyterminated. 45. *YoualsoconsumetheWM_QUITmessageinsteadofre-postingit 46. *sothattheapplicationcontinuestorun. 47. * 48. *Essentially,youhavetrickedthenestedmessageloopinto 49. *determiningthattheapplicationisterminating.Whenthequitmessage 50. *returns,youconsumethequitmessage.Thismethodeffectivelycancels 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. *Thisfunctioncausesthemessageboxtoexitbecausethemessagebox 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*values. 92. * 93. */94. intTimedMessageBox(HWNDhwndOwner, 95. LPCTSTRpszMessage, 96. LPCTSTRpszTitle, 97. UINTflags, 98. DWORDdwTimeout) 99. 100. UINTidTimer; 101. intiResult; 102. 103. g_hwndTimedOwner=NULL; 104. g_bTimedOut=FALSE; 105. 106. if(hwndOwner&IsWindowEnabled(hwndOwner) 107. g_hwndTimedOwner=hwndOwner; 108. 109. /Setatimertodismissthemessagebox. 110. idTimer=SetTimer(NULL,0,dwTimeout,(TIMERPROC)MessageBoxTimer); 111. 112. iResult=MessageBox(hwndOwner,pszMessage,pszTitle,flags); 113. 114. /Finishedwiththetimer. 115. KillTimer(NULL,idTimer); 116. 117. /SeeifthereisaWM_QUITmessageinthequeueifwetimedout. 118. /Eatthemessagesowedonotquitthewholeapplication. 119. if(g_bTimedOut) 120. 121. MSGmsg; 122. PeekMessage(&msg,NULL,WM_QUIT,WM_QUIT,PM_REMOVE); 123. iResult=-1; 124. 125. 126. returniResult; 127. 128. 129. /* 130. * 131. *WinMain 132. * 133. *Programentrypoint.DemonstrateTimedMessageBox(). 134. * 135. */136. intWINAPIWinMain(HINSTANCEhinst, 137. HINSTANCEhinstPrev, 138. LPSTRpszCmdLine, 139. intnCmdShow) 140. 141. 142. UINTuiResult; 143. 144. /Asktheuseraquestion.Givetheuserfivesecondsto 145. /answerthequestion. 146. uiResult=TimedMessageBox(NULL, 147. Doesatrianglehavethreesides?, 148. Quiz, 149. MB_YESNO, 150. /NULLfirstparameterisimportant. 151. 5000); 152. 153. switch(uiResult) 154. caseIDYES: 155. MessageBox(NULL, 156. Thatsright!, 157. Result, 158. MB_OK); 159. break; 160. 161. caseIDNO: 162. MessageBox(NULL, 163. Believeitornot,triangles164. reallydohavethreesides., 165. Result, 166. MB_OK); 167. break; 168. 169. case-1: 170. MessageBox(NULL, 171. Isensedsomehesitationthere.172. ThecorrectanswerisYes., 173. Result, 174. MB_OK); 175. break; 176. 177. 178. return0; 179. 2、第二種方法:使用手動創(chuàng)建的對話框新建一個對話框,添加一個靜態(tài)文本控件(顯示內(nèi)容),如下圖:將Static控件關(guān)聯(lián)CString類型變量為m_strText、并為該對話框添加新類CMSGBox,再添加WM_TIMER消息:view plaincopy to clipboardprint?1. voidCMSGBox:OnTimer(UINTnIDEvent) 2. 3. /TODO:Addyourmessagehandlercodehereand/orcalldefault 4. if(1=nIDEvent) 5. 6. KillTimer(1); 7. EndDialog(IDOK); 8. 9. CDialog:OnTimer(nIDEvent); 10. PS:我覺得此處代碼可以改成這樣,就可以設(shè)定多個定時器(我可沒測試)view plaincopy to clipboardprint?1. voidCMSGBox:OnTimer(UINTnIDEvent) 2. 3. /TODO:Addyourmessagehandlercodehereand/orcalldefault 4. if(nIDE
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025至2030中國肺內(nèi)窺鏡檢查設(shè)備行業(yè)產(chǎn)業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 2025學年六年級語文下冊教學實施計劃
- 2025至2030中國耳鼻喉科手術(shù)顯微鏡行業(yè)產(chǎn)業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 2025至2030中國羊毛混紡地毯行業(yè)發(fā)展趨勢與行業(yè)市場深度研究與戰(zhàn)略咨詢分析報告
- 2025至2030中國網(wǎng)絡(luò)視頻錄像機行業(yè)發(fā)展趨勢分析與未來投資戰(zhàn)略咨詢研究報告
- 2025至2030中國網(wǎng)上科研平臺行業(yè)運營趨勢與前景動態(tài)研究報告
- 深度學習在自動駕駛領(lǐng)域中的圖像識別技術(shù)
- 2025至2030中國繡花坯布行業(yè)供需趨勢及投資風險報告
- 2025小學二年級班主任學生考勤管理計劃
- 腦波控制睡眠系統(tǒng)的研發(fā)進展與市場前景展望
- 綠山墻的安妮-練習答案(完整版)資料
- 2022年小學美術(shù)教師進城(選調(diào))招聘考試模擬試題(共五套)
- 貴陽小升初分班全真模擬測A卷
- GB/T 77-2007內(nèi)六角平端緊定螺釘
- 中華人民共和國安全生產(chǎn)法
- 九年一貫制學校教育教學管理制度匯編
- 《C++語言基礎(chǔ)》全套課件(完整版)
- 鋼筋混凝土框架結(jié)構(gòu)設(shè)計講義
- 保溫材料進場質(zhì)量檢驗表
- DG-TJ 08-2122-2021 保溫裝飾復合板墻體保溫系統(tǒng)應(yīng)用技術(shù)標準
- GB∕T 23937-2020 工業(yè)硫氫化鈉
評論
0/150
提交評論