Hehe, I have fifty things to do today, but you happened to ask for something fun, so 49 jobs get pushed back and this gets done:
Code: Select all
;===================================================================================
; Program: Yet another timed messagebox sample - Remaining Seconds Version
; 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, g_dwTimeout, g_Quiz_ButtonHandle
Procedure MessageBoxStatus(hwnd, uiMsg, idEvent, dwTime)
Static numseconds=0
Static firstrun=1
If firstrun
numseconds = g_dwTimeout / 1000
firstrun = 0
EndIf
numseconds-1
If IsWindow_(g_Quiz_ButtonHandle)
SetWindowText_(g_Quiz_ButtonHandle, "&Yes = "+Str(numseconds))
Else
KillTimer_(hwnd, idEvent)
firstrun = 1
EndIf
If numseconds < 0
KillTimer_(hwnd, idEvent)
firstrun = 1
EndIf
EndProcedure
Procedure FindButton(hwnd, param)
ButtonText.s = Space(50)
GetWindowText_(hwnd, @ButtonText, 49)
If ButtonText = PeekS(param)
g_Quiz_ButtonHandle = hwnd
ProcedureReturn 0
Else
ProcedureReturn 1
EndIf
EndProcedure
Procedure WindowProc(hwnd, msg, wparam, lparam)
result = #PB_ProcessPureBasicEvents
Select msg
Case #WM_ACTIVATE
If wparam & $FFFF = #WA_INACTIVE
class.s = Space(50)
caption.s = Space(50)
GetClassName_(lparam, @class, 49)
GetWindowText_(lparam, @caption, 49)
If class = "#32770"
If caption = "Quiz"
EnumChildWindows_(lparam, @FindButton(), @"&Yes")
If IsWindow_(g_Quiz_ButtonHandle)
SetWindowText_(g_Quiz_ButtonHandle, "&Yes = "+Str(g_dwTimeout/1000))
EndIf
idStatusTimer.l = SetTimer_(#Null, 0, 1000, @MessageBoxStatus())
EndIf
EndIf
EndIf
EndSelect
ProcedureReturn result
EndProcedure
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
g_dwTimeout = dwTimeout
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")
SetWindowCallback(@WindowProc())
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