|
可以自己定义函数SQAMsgbox,指定时间后对话框自动消失
在论坛里有人发的贴,你可以搜一下函数名
SQAMsgbox “指定时间消失”,“标题”,120,120秒后对话框自动消失
Global iTime as Integer 'used by SQAMsgBox function
'Dim TotalTime As Integer 'used by TimedMsgBox sub
Declare Function TimedDlgFunc(id As String, Action As Integer, SuppValue As Long) As Integer
'----------------------------------------------------------------
'TimedDlgFunc
'============
'function to process user actions in the SQAMsgBox dialog box
'(original function by Andy Tinkham, modified by Paul Downes)
'input : id = identifies the dialog control that triggered the call
' to the dialog function
' : Action = integer from 1 to 5 identifying the reason why the
' dialog function was called
' : SuppValue = specific info about why the dialog function was called
'returns :
Function TimedDlgFunc(id As String, Action As Integer, SuppValue As Long) As Integer
Static StartTime
Dim EndTime
Dim vTimeoutValue as Variant
Select Case Action
Case 1
StartTime = Timer
'Check to see if StartTime + TotalTime is greater than 86400
'(the total number of seconds in a day). If it is, change the
'value so that it is negative so that when the Timer function
'wraps back to 0 at midnight, the dialog still goes away at the
'appropriate time.
If StartTime + iTime >= 86400 Then
StartTime = 86400 - StartTime - iTime
End If
TimedDlgFunc = 1
Case 2
Select Case SuppValue
Case 1
DlgEnd -1
Case 2
DlgEnd 0
Case Else
TimedDlgFunc = 0
End Select
Case 3
TimedDlgFunc = 1
Case 4
TimedDlgFunc = 1
Case 5
EndTime = Timer
If (EndTime - StartTime) >= iTime Then
DlgEnd -1
End If
vTimeoutValue = Format(iTime - (EndTime - StartTime), "#.#")
DlgText DlgControlID("txtTimeValue"), CStr(vTimeoutValue)
TimedDlgFunc = 1
End Select
End Function
'----------------------------------------------------------------
'SQAMsgBox
'=========
'timed message box; displays timeout countdown; if user selects "OK" or on timeout,
'returns sqaPass; if user selects "Cancel", returns sqaFail
'input : sMsgText = message to display
' : vMsgCaption = (optional) dialog box caption
' : vTimeOut = (optional) timeout period in seconds (default = 20)
'returns : sqaPass on timeout or when OK button selected; sqaFail if Cancel selected
Function SQAMsgBox(sMsgText as String, Optional vMsgCaption as Variant, Optional vTimeOut as Variant) as Integer
Dim Result as Integer
Dim TotalTime As Integer
Dim sCmdText as String
Dim sTimeoutText as String
Dim vValue as Variant
'command message displayed
sCmdText = "Press OK to continue execution, Cancel to stop script."
'set defaults for optional parameters, if missing
If IsMissing(vMsgCaption) Then
vMsgCaption = "SQAMsgBox"
End If
If IsMissing(vTimeOut) Then
vTimeOut = 20 'seconds
End If
sTimeoutText = "Timeout: "
'-----
Begin Dialog dlgMsgBox 200, 80, vMsgCaption, .TimedDlgFunc
GroupBox 5, 2, 190, 40, "", .grpMsgTxt
Text 15, 11, 175, 25, sMsgText, .txtMsgText
Text 15, 47, 180, 20, sCmdText, .txtCmdText
'--------------
' Button 40, 60, 40, 14, "&OK", .btnOK
' Button 120, 60, 40, 14, "&Cancel", .btnCancel
'--------------
' Button 100, 60, 40, 14, "&OK", .btnOK
' Button 150, 60, 40, 14, "&Cancel", .btnCancel
' Text 15, 63, 30, 10, sTimeoutText, .txtTimeText
' Text 50, 63, 20, 10, vTimeout, .txtTimeValue
'--------------
Button 20, 60, 40, 14, "&OK", .btnOK
Button 140, 60, 40, 14, "&Cancel", .btnCancel
Text 78, 63, 30, 10, sTimeoutText, .txtTimeText
Text 108, 63, 20, 10, vTimeout, .txtTimeValue
End Dialog
'-----
Dim TimedDlg As dlgMsgBox
iTime = CInt(vTimeOut)
Result = Dialog(TimedDlg)
If Result = 2 Then
SQAMsgBox = sqaFail
Else
SQAMsgBox = sqaPass
End If
End Function
'----------------------------------------------------------------
' Original function, by Andy Tinkham
'* Syntax:
'*
'* Call TimedMsgBox ("message", "caption", 20)
'*
'Sub TimedMsgBox (MsgText As String, MsgCaption As String, TimeToShow As Integer)
' Begin Dialog dlgMsgBox 200, 100, MsgCaption, .TimedDlgFunc
' Text 15, 12, 170, 80, MsgText, .txtMsgText
' Button 80, 80, 40, 14, "OK", .btnOK
' End Dialog
' Dim TimedDlg As dlgMsgBox
' TotalTime = TimeToShow
' Dialog TimedDlg
'End Sub
'---------------------------------------------------------------- |
|