码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2020-10-29 10:00:48      阅读:29      评论:0      收藏:0      [点我收藏+]

标签:get   crlf   box   var   user   any   err   ons   vbo   

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提示窗口超时限后自动关闭

标签:get   crlf   box   var   user   any   err   ons   vbo   

原文地址:https://blog.51cto.com/12815848/2544645

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!