注册 登录
编程论坛 VB6论坛

请高手帮助修改下,空闲1分钟或者5分钟,自动关闭指定网页

e3bnsd 发布于 2012-12-13 21:45, 709 次点击
只有本站会员才能查看附件,请 登录
程序代码:
Private Declare Function GetLastInputInfo Lib "user32" (plii As LASTINPUTINFO) As Boolean
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Dim hwnd1, hwnd2, hwnd3 As Long
Dim winHwnd As Long
Dim RetVal As Long
Private Const WM_CLOSE As Long = &H10
Private Type LASTINPUTINFO
    cbSize As Long
    dwTime As Long
   
End Type


Private Sub Command1_Click()
Dim lii As LASTINPUTINFO
    lii.cbSize = Len(lii)
        Do
            If GetLastInputInfo(lii) Then Label1 = "系统空闲时间:" & (GetTickCount - lii.dwTime) / 60000 & ""
            DoEvents
        Loop
End Sub

Private Sub Form_Load()
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
hwnd1 = FindWindow("IEFrame", "VB6论坛-编程论坛 - Windows Internet Explorer")
winHwnd = FindWindow(vbNullString, "VB6论坛-编程论坛 - Windows Internet Explorer")
Debug.Print winHwnd
Label2.Caption = hwnd1
If hwnd1 <> 0 Then
Call a
End If
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
End If
End Sub
6 回复
#2
e3bnsd2012-12-13 22:05
在 这 加一个判断 行不 ?If hwnd1 <> 0  and   (GetTickCount - lii.dwTime) / 60000 >1  Then ..............
#3
Artless2012-12-14 12:45
什么问题?
#4
e3bnsd2012-12-14 14:19
请高手帮助修改下,空闲1分钟或者5分钟,自动关闭指定网页

版主,我想做一个:系统闲置 1分钟(为了测试方便,先暂时定为1分钟),就关闭指定的网页。

判断系统闲置时间的代码 和 工程文件 都有了。  就是 怎么修改下?  要在  if 条件  那 加个判断吧? 怎么写呢?    怎么把 空闲的时间(GetTickCount - lii.dwTime) / 60000   转化为 数值呢?

[ 本帖最后由 e3bnsd 于 2012-12-14 14:34 编辑 ]
#5
Artless2012-12-14 18:00
If hwnd1 <> 0 and (GetTickCount - lii.dwTime) / 60000=1 Then
#6
e3bnsd2012-12-15 00:37
If hwnd1 <> 0 and (GetTickCount - lii.dwTime) / 60000=1 Then    这样修改提示错误:
只有本站会员才能查看附件,请 登录



改成 这样  :And Val("(GetTickCount - lii.dwTime) / 60000") = 1  没错误提示,但是 没起作用。
#7
a8141532013-04-30 06:03
    With CreateObject("Shell.Application")
        For Each oWin In .Windows
            If LCase(TypeName(oWin.document)) = "htmldocument" Then
                If oWin.locationname Like "请高手帮助修改下*" Then   '利用like可以实现模糊匹配标题,locationname 换成 locationurl 可以匹配网址
                    oWin.document.parentwindow.eval "javascript:window.opener=null;window.open('','_self');window.close();"'调用javascript函数关闭
                    'oWin.Quit'这个是直接关闭
                End If
            End If
        Next
    End With
1