www.pudn.com > 1.rar > Form1.frm, change:2010-07-13,size:2183b


VERSION 5.00 
Begin VB.Form Form1  
   Caption         =   "Form1" 
   ClientHeight    =   4980 
   ClientLeft      =   60 
   ClientTop       =   345 
   ClientWidth     =   6975 
   LinkTopic       =   "Form1" 
   ScaleHeight     =   4980 
   ScaleWidth      =   6975 
   StartUpPosition =   3  '窗口缺省 
   Begin VB.TextBox Text1  
      Height          =   615 
      Left            =   1320 
      TabIndex        =   0 
      Text            =   "Text1" 
      Top             =   600 
      Width           =   2535 
   End 
   Begin VB.Timer Timer1  
      Interval        =   50 
      Left            =   960 
      Top             =   1920 
   End 
End 
Attribute VB_Name = "Form1" 
Attribute VB_GlobalNameSpace = False 
Attribute VB_Creatable = False 
Attribute VB_PredeclaredId = True 
Attribute VB_Exposed = False 
' 获得鼠标和键盘动作的Api 
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean 
Private Type LASTINPUTINFO 
    cbSize   As Long 
    dwTime   As Long 
End Type 
' 获得当前时间 单位为毫秒 
Private Declare Function GetTickCount Lib "kernel32" () As Long 
 
' 控制系统关机的Api 
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long 
Const EWX_SHUTDOWN = 1 
Const EWX_LOGOFF = 0 
Const EWX_REBOOT = 2 
Const EWX_FORCE = 4 
 
Dim mEvent      As LASTINPUTINFO 
Dim StopTime    As Long     ' 鼠标和键盘,开始无动作的时间 
Dim PrvEvent    As Long     ' 上一次鼠标或者键盘的状态 
 
Private Sub Timer1_Timer() 
    mEvent.cbSize = Len(mEvent) 
     
    GetLastInputInfo mEvent 
    Debug.Print mEvent.dwTime 
    ' 判断鼠标和键盘的状态,如果状态改变,则重新设置监视时间,保存当前状态 
    If mEvent.dwTime <> PrvEvent Then 
        PrvEvent = mEvent.dwTime 
        StopTime = GetTickCount 
                   Text1.Text = "d在动" 
 
         
    Else 
        ' 如果当前时间与开始监视时间超过3,600,000 Ms 则关机. 
        If (GetTickCount - StopTime) >= (1 * 5 * 100) Then 
           ' Call ExitWindowsEx(EWX_LOGOFF Or EWX_FORCE Or EWX_SHUTDOWN, 0) '关机 
            
           Text1.Text = "没有动" 
            
        End If 
    End If 
     
End Sub