各位大侠,大家好,小弟遇到个问题,我是VB新手,一直解决不了,所以来这里请教一下大家。
废话少说,先附上代码:
Private Sub Timer1_Timer()
    nowTime = Time
    Me.Label2.Caption = Time
    If Option1.Value Then
        If DateDiff("s", nowTime, txtTime) = 60 Then
            Timer1.Enabled = True
            If MsgBox("距离关机时间还有一分钟,是否取消?", vbYesNo + vbInformation, "关机确认") = vbYes Then
                Timer1.Enabled = False
            End If
        End If
        If DateDiff("s", nowTime, txtTime) = 0 Then
            ShutDownPC True
            Timer1.Enabled = False
        End If
    End If
End Sub我是想在离关机前一分钟弹出提示,如果按了确定按钮呢,是可以取消定时关机的。现在的问题是,我想如果这一分钟里没有任何操作,即没有按确定也没有按取消按钮的情况下继续计时,然后一分钟后关闭电脑。现在这段代码是如果没有操作的话也不执行后面的代码,希望哪位高手帮我看看,先谢了!
在线等,谢谢!

解决方案 »

  1.   

    用MessageBox,弹出对话框但不会挂起线程
      

  2.   


    Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVaL hwnd As Long, ByVaL lpText As String, ByVaL lpCaption As String, ByVaL wType As Long) As Long
    Private Sub Timer1_Timer()
      nowTime = Time
      Me.Label2.Caption = Time
      If Option1.Value Then
      If DateDiff("s", nowTime, txtTime) = 60 Then
      Timer1.Enabled = True
      If MessageBox("距离关机时间还有一分钟,是否取消?", vbYesNo + vbInformation, "关机确认") = vbYes Then
      Timer1.Enabled = False
      End If
      End If
      If DateDiff("s", nowTime, txtTime) = 0 Then
      ShutDownPC True
      Timer1.Enabled = False
      End If
      End If
    End Sub
      

  3.   

    写错了 。
    Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVaL hwnd As Long, ByVaL lpText As String, ByVaL lpCaption As String, ByVaL wType As Long) As Long
    Private Sub Timer1_Timer()
      nowTime = Time
      Me.Label2.Caption = Time
      If Option1.Value Then
      If DateDiff("s", nowTime, txtTime) = 60 Then
      Timer1.Enabled = True
      If MessageBox(me.hwnd,"距离关机时间还有一分钟,是否取消?", "关机确认", vbYesNo + vbInformation) = vbYes Then
      Timer1.Enabled = False
      End If
      End If
      If DateDiff("s", nowTime, txtTime) = 0 Then
      ShutDownPC True
      Timer1.Enabled = False
      End If
      End If
    End Sub
      

  4.   

    错了错了,是我没看到你代码里的那个me.hwnd.
    我试试,先谢了
      

  5.   

    不用msgbox,自己做个弹出窗体吧。