;*************************************************************************** ; Program: Yet another timed messagebox sample ; Source: http://support.microsoft.com/?scid=181934 ; PB version by: netmaestro ; Date: March 21, 2007 ; Applies to: Anyone who likes timed message boxes ; Disclaimer: Hardly any animals were harmed during the creation of ; this software. (one who whined got his feelings hurt) ;*************************************************************************** #MessageBox_Timeout = -1 Global g_hwndTimedOwner Global g_bTimedOut Procedure MessageBoxTimer(hwnd, uiMsg, idEvent, dwTime) g_bTimedOut = #True If g_hwndTimedOwner EnableWindow_(g_hwndTimedOwner, #True) EndIf PostQuitMessage_(0) EndProcedure Procedure TimedMessageBox(hwndOwner, pszMessage.s, pszTitle.s, flags, dwTimeout) Protected idTimer.l, iResult.l g_hwndTimedOwner = #Null g_bTimedOut = #False If hwndOwner And IsWindowEnabled_(hwndOwner) g_hwndTimedOwner = hwndOwner EndIf idTimer.l = SetTimer_(#Null, 0, dwTimeout, @MessageBoxTimer()) iResult.l = MessageBox_(hwndOwner, pszMessage, pszTitle, flags) KillTimer_(#Null, idTimer) If g_bTimedOut PeekMessage_(@msg.MSG, #Null, #WM_QUIT, #WM_QUIT, #PM_REMOVE) iResult = #MessageBox_Timeout EndIf ProcedureReturn iResult EndProcedure ; Little test... OpenWindow(0,0,0,320,240,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu) CreateGadgetList(WindowID(0)) ButtonGadget(0,100,200,100,25,"Do it") Repeat ev = WaitWindowEvent() If ev = #PB_Event_Gadget uiResult = TimedMessageBox(#Null, "Does a triangle have three sides?", "Quiz", #MB_YESNO, 5000) ; // NULL first parameter is important. Select uiResult Case #IDYES MessageBox_(#Null, "That's right!", "Result", #MB_OK) Case #IDNO MessageBox_(#Null, "Believe it or not, triangles really do have three sides.", "Result", #MB_OK) Case #MessageBox_Timeout MessageBox_(#Null, "I sensed some hesitation there. The correct answer is Yes.", "Result", #MB_OK) EndSelect EndIf Until ev = #WM_CLOSE