急求vb编写倒计时关机代码,要求窗体上显示倒计时剩余秒数,最好窗体一启动就开始倒计时关机,谢谢,。
Sub Timer1_Timer()
Text3 = IIf(ss < 10, "0" & ss, "" & ss)
Text2 = IIf(mm < 10, "0" & mm, "" & mm)
Text1 = IIf(hh < 10, "0" & hh, "" & hh)
STRmm = Text1.Text & Text2.Text & Text3.Text
P(0) = Mid(STRmm, 1, 1)
P(1) = Mid(STRmm, 2, 1)
P(2) = Mid(STRmm, 3, 1)
P(3) = Mid(STRmm, 4, 1)
P(4) = Mid(STRmm, 5, 1)
P(5) = Mid(STRmm, 6, 1)
For i = 0 To 5
Select Case P(i)
Case "0"
Image6(i).Picture = LoadResPicture(110, 0)
Case "1"
Image6(i).Picture = LoadResPicture(101, 0)
Case "2"
Image6(i).Picture = LoadResPicture(102, 0)
Case "3"
Image6(i).Picture = LoadResPicture(103, 0)
Case "4"
Image6(i).Picture = LoadResPicture(104, 0)
Case "5"
Image6(i).Picture = LoadResPicture(105, 0)
Case "6"
Image6(i).Picture = LoadResPicture(106, 0)
Case "7"
Image6(i).Picture = LoadResPicture(107, 0)
Case "8"
Image6(i).Picture = LoadResPicture(108, 0)
Case "9"
Image6(i).Picture = LoadResPicture(109, 0)
End Select
Next
'将时间值赋给SMALLFORM窗体显示
Sss = IIf(ss < 10, "0" & ss, "" & ss)
Smm = IIf(mm < 10, "0" & mm, "" & mm)
Shh = IIf(hh < 10, "0" & hh, "" & hh)
SmallForm.Label1.Caption = "剩余:" & Shh & "时" & Smm & "分" & Sss & "秒"
ss = ss - 1
If hh = 0 And mm = 0 And ss = -1 Then
Select Case Combo1.ListIndex
Case 0
'反回桌面锁屏代码
'MsgBox Combo1.List(0)
'以下代码返回桌面
keybd_event VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0 ' 按下
DoEvents
keybd_event vbKeyM, 0, KEYEVENTF_EXTENDEDKEY, 0
DoEvents
keybd_event vbKeyM, 0, KEYEVENTF_KEYUP, 0 ' 弹起
DoEvents
keybd_event VK_LWIN, 0, KEYEVENTF_KEYUP, 0 ' 弹起
'以下代码锁屏
LockWorkStation
Case 1 '重启计算机
Reboot
Case 2 '关闭计算机
ShutDown
Case 3 '注销系统
ExitWindowsEx EWX_LOGOFF, 0
Case 4 '执行程序
ShellExecute 0, "open", CommonDialog1.FileName, "", Left(CommonDialog1.FileName, _
Len(CommonDialog1.FileName) - Len(CommonDialog1.FileTitle)), 1
Case 5 '关闭程序
Shell "cmd.exe /c taskkill /f " & KillString
End Select
t.cbSize = Len(t)
t.hWnd = pic.hWnd
t.uId = 1&
Shell_NotifyIcon NIM_DELETE, t
End
End If
If ss = -1 And mm > -1 Then mm = mm - 1: ss = 59
If mm = -1 And hh > 0 Then hh = hh - 1: mm = 59
'每10分钟全屏截图一次存入在目录文件夹ScreenPotho中
If mm Mod 10 = 0 And ss = 3 Then
Call ScreenPohto
End If
'最后一分钟播放音乐提醒
If hh = 0 And mm = 0 And ss <= 59 And Aminute.Checked = True And Plays = 0 Then
Plays = sndPlaySound("warning.wav", SND_LOOP Or SND_ASYNC) '播放
End If
End Sub
Dim Sec As Long
Private Sub Form_Load()
Timer1.Interval = 1000
Sec = 600 ‘这里修改为你需要的倒计时时间
Label1 = Sec & "秒后关机"
End Sub
Private Sub Timer1_Timer()
Sec = Sec - 1
Label1 = Sec & "秒后关机"
If Sec <= 0 Then
Shell "Shutdown -s -f -t 0"
End If
End Sub
Timer1.Interval = 1000
Text1.Text = 10 '预设10秒倒计时
End Sub
Private Sub Timer1_Timer()
Text1.Text = Text1.Text - 1
If Text1.Text = 0 Then Shell "shutdown /t 0 /s", vbNormalFocus
End Sub