VB Msgbox提示窗口超时限后自动关闭

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB Msgbox提示窗口超时限后自动关闭相关的知识,希望对你有一定的参考价值。

Public Function F_Msgbox_time(para_msg As String, title1 As String) As Long
    On Error Resume Next
    Dim hwnd As Long
    Timer3.Enabled = True
    F_Msgbox_time = MsgBox(para_msg, vbOKCancel + vbApplicationModal, title1)
    Timer3.Enabled = False
End Function
//----------------------F_Msgbox_time() -------------------------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_KEYDOWN = &H100
//Private Const WM_CLOSE = &H10
Private Const MsgTitle As String = "MyshutdownMsg"

//-----------------------------------------------------------------------
Private Sub Timer3_Timer()
    On Error Resume Next
    Dim hwnd As Long
    hwnd = FindWindow(vbNullString, MsgTitle)
    Call PostMessage(hwnd, WM_KEYDOWN, 13, 0&)
//  Call SendMessage(hwnd, WM_CLOSE, 0, ByVal 0&)
End Sub
Private Sub Form_Load()
        Timer1.Enabled = True
        Timer1.Interval = 60000
        Timer2.Enabled = True
        Timer2.Interval = 1000
        Timer3.Enabled = False
        Timer3.Interval = 60000
End Sub
//调用格式
                If F_Msgbox_time(" 网管监控提醒您:系统将在1分钟后关机!" & vbCrLf & vbCrLf & _
                                 " [确定] 立即关机, [取消] 忽略此操作。", MsgTitle) = 1 Then
                    Call F_Get_Shutsig(public_IP_STRING, "1")
                    Call F_Get_Shutsig(public_IP_STRING, "3")
                    Shell "shutdown -s -t 10"
                    End
                Else
                    sig0 = F_Get_Shutsig(public_IP_STRING, "2")
                End If
//应用格式

Public Sub P_OPEN_MSG(msgname As Variant)
    On Error Resume Next
    Dim para1 As String
    para1 = msgname
    Call F_Msgbox_time(para1, MsgTitle)
End Sub

以上是关于VB Msgbox提示窗口超时限后自动关闭的主要内容,如果未能解决你的问题,请参考以下文章

用VB运行工程时,双击打开窗体文件,VB就自动关闭了,毫无提示,在此之前还出现对象库未注册,高手,咋办

vb编的小程序,关闭窗口时 弹出的窗口提示 如何改变

vb6.0 怎么把msgbox设置成有是、否、取消三个按钮呢,菜鸟路过,求帮助。代码又是怎么写的呢??

EXCEL VBA 窗体显示期间不执行下面代码,也不影响操作工作表?

asp网页中,如何实现点击按钮弹出对话框,然后点击“确定”关闭窗口,点击“取消”返回?尽快,非常感谢!

VB如何实现执行某程序,弹出对话框选择是不是要执行,点击是则执行,否则不执行