Display a message box with a timeout value

前端 未结 5 2061
轻奢々
轻奢々 2020-12-06 02:55

The question comes from code like this.

Set scriptshell = CreateObject(\"wscript.shell\")
    Const TIMEOUT_IN_SECS = 60
    Select Case scriptshell.popup(\"         


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 03:53

    Going with Answer A. the Win32 solution. This meets the requirements, and is robust from testing so far.

    Declare Function MessageBoxTimeout Lib "user32.dll" Alias "MessageBoxTimeoutA" ( _ 
    ByVal hwnd As Long, _ 
    ByVal lpText As String, _ 
    ByVal lpCaption As String, _ 
    ByVal uType As Long, _ 
    ByVal wLanguageID As Long, _ 
    ByVal lngMilliseconds As Long) As Long 
    
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _ 
    ByVal lpClassName As String, _ 
    ByVal lpWindowName As String) As Long 
    
    Public Sub MsgBoxDelay() 
        Const cmsg As String = "Yes or No? leaving this window for 1 min is the same as clicking Yes." 
        Const cTitle As String = "popup window" 
        Dim retval As Long 
        retval = MessageBoxTimeout(FindWindow(vbNullString, Title), cmsg, cTitle, 4, 0, 60000) 
    
        If retval <> 7 Then 
            Call MethodFoo 
        End If 
    
    End Sub
    

提交回复
热议问题