1、整人 VB 小程序:倒计时关机程序启动,会进入倒计时关机状态。除非用户输入特定字符(如:我是大傻瓜),否则程序不会结束。 以下代码在 VB6 调试通过。首先,在窗体放置 6 个控件,不需设置任何属性: Label1、Label2、Label3、Command1、Text1、Timer1需修改 * 处的关机倒计时时间 和 要求用户输入的字符Private Declare Function ExitWindowsEx Lib “user32“ (ByVal uFlags As Long, ByVal dwReserved As Long) As LongConst EWX_SHUTDOWN = 1
2、Dim nJiShi As String, nOK As BooleanPrivate Declare Function SetWindowPos Lib “user32“ (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As LongPrivate Const HWND_Top = 0 hWndInsertAfter 参数:Z 序列的顶部Private C
3、onst HWND_TopMost = -1 最上Private Const SWP_NoSize = &H1 wFlags 参数Private Const SWP_NoMove = &H2Private Const SWP_NoZorder = &H4Private Const SWP_ShowWindow = &H40Private Const SWP_HideWindow = &H80Private Sub Form_Load()Dim SnJiShi = “0:10:05“ * 设置关机时间,可修改Label1.AutoSize = True: Label1.Caption = “请输
4、入正确字符,否则自动关机。你是什么人?“Label2.AutoSize = True: Label2.Caption = “Label3.AutoSize = True: Label3.Caption = “: Label3.ForeColor = 255Timer1.Enabled = True: Timer1.Interval = 1000Me.Caption = “自动关机“Text1.Text = “: Command1.Caption = “确定(&Y)“S = Label1.HeightLabel2.Move S, S: Label1.Move S, S * 2.5Text1.Mo
5、ve S, S * 4, S * 10, S: Label3.Move S, S * 7Command1.Move S * 8, S * 6, S * 5, S * 2End SubPrivate Sub Command1_Click()If Text1.Text =“我是大傻瓜 “ or Text1.Text =“我是大笨蛋“ Then * 要求用户输入的字符MsgBox “回答正确:你是大笨蛋!“, vbInformation, “回答问题“nOK = True: Unload MeElseIf Trim(Text1.Text) = “ ThenLabel3.Caption = “请回答问
6、题“ElseLabel3.Caption = “回答错误“End IfEnd IfEnd SubPrivate Sub Form_Unload(Cancel As Integer)If Not nOK Then Cancel = 1End SubPrivate Sub Timer1_Timer()Dim nTime As String, S As LongCall WinInTop(Me.hwnd) 使本程序显示在最前面nJiShi = DateAdd(“s“, -1, nJiShi)Label2.Caption = “关机到计时:“ & nJiShiS = Format(nJiShi, “hhmmss“)If S 0 Then Exit SubExitWindowsEx EWX_SHUTDOWN, 0nOK = TrueEnd SubPrivate Sub WinInTop(hwnd As Long)Dim wAfter As Long, wFlags As LongwAfter = HWND_TopMostwFlags = SWP_NoSize + SWP_NoMoveSetWindowPos hwnd, wAfter, 0, 0, 0, 0, wFlagsEnd Sub