




已閱讀5頁(yè),還剩6頁(yè)未讀, 繼續(xù)免費(fèi)閱讀
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
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、第二種方法:使用手動(dòng)創(chuàng)建的對(duì)話框新建一個(gè)對(duì)話框,添加一個(gè)靜態(tài)文本控件(顯示內(nèi)容),如下圖:將Static控件關(guān)聯(lián)CString類型變量為m_strText、并為該對(duì)話框添加新類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:我覺(jué)得此處代碼可以改成這樣,就可以設(shè)定多個(gè)定時(shí)器(我可沒(méi)測(cè)試)view plaincopy to clipboardprint?1. voidCMSGBox:OnTimer(UINTnIDEvent) 2. 3. /TODO:Addyourmessagehandlercodehereand/orcalldefault 4. if(nIDE
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 商業(yè)晚會(huì)活動(dòng)方案
- 圖文公司營(yíng)銷策劃方案
- 圖書營(yíng)銷大賽活動(dòng)方案
- 國(guó)慶周大?;顒?dòng)方案
- 商家線上互動(dòng)活動(dòng)方案
- 呵護(hù)心靈活動(dòng)方案
- 國(guó)企內(nèi)部互幫活動(dòng)方案
- 商場(chǎng)年度活動(dòng)方案
- 國(guó)慶康體活動(dòng)策劃方案
- 團(tuán)委精神文明月活動(dòng)方案
- 頸椎腫瘤的護(hù)理
- 2025至2030中國(guó)不銹鋼精密帶材行業(yè)前景預(yù)測(cè)及發(fā)展趨勢(shì)預(yù)判報(bào)告
- 無(wú)人機(jī)駕駛員雇傭合同協(xié)議
- 湖南省長(zhǎng)沙市華益中學(xué)2023-2024學(xué)年八年級(jí)下學(xué)期期末考試英語(yǔ)試卷(含答案)
- (高清版)DB13∕T 2937-2019 非煤礦山雙重預(yù)防機(jī)制建設(shè)規(guī)范
- 電動(dòng)船舶生產(chǎn)線項(xiàng)目可行性研究報(bào)告(范文參考)
- 浙江寧波歷年中考作文題與審題指導(dǎo)(2007-2021)
- 大學(xué)生醫(yī)學(xué)健康科普演講
- 2025國(guó)開(kāi)電大《管理英語(yǔ)1》綜合測(cè)試形考任務(wù)答案
- 冶金天車作業(yè)安全培訓(xùn)
- 《馬克思主義基本原理概論》課后思考題及答案
評(píng)論
0/150
提交評(píng)論