网页刷新器

Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long

Private Const GW_HWNDLAST = 1
Private Const GW_HWNDNEXT = 2

Function GetWin(webadd As String) As String
   On Error Resume Next
  
   Dim NhWnd As Long
   Dim Length, WinTitle$
   Dim OkWin As String
  
   NhWnd = GetWindow(hwnd, GW_HWNDFIRST)
  
   While NhWnd <> 0
       Length = GetWindowTextLength(NhWnd)
       WinTitle$ = Space$(Length + 1)
      
       Length = GetWindowText(NhWnd, WinTitle$, Length + 1)
      
       If InStr(LCase(WinTitle$), webadd) > 0 Then
           OkWin = OkWin & "//" & NhWnd
       End If
   
       NhWnd = GetWindow(NhWnd, GW_HWNDNEXT)
   Wend
  
   GetWin = OkWin
End Function


Sub SendInfo(webaddr As String)
   On Error Resume Next
  
   Dim OkWin, hCount
   OkWin = GetWin(webaddr)
   'MsgBox OkWin
   If Len(OkWin) > 0 Then
       OkWin = Split(OkWin, "//")
       For hCount = 0 To UBound(OkWin)
           If Len(OkWin(hCount)) > 0 Then
               'MsgBox OkWin(hCount)
               'MsgBox GetWinName(OkWin(hCount))
               AppActivate GetWinName(OkWin(hCount))
               SendKeys "{F5}"
           End If
       Next
   End If
End Sub

Function GetWinName(ByVal WinID As Long) As String
   On Error Resume Next
  
   If WinID < 1 Then Exit Function
   Dim Length, WinTitle$
   Length = GetWindowTextLength(WinID)
   WinTitle$ = Space$(Length + 1)
   Length = GetWindowText(WinID, WinTitle$, Length + 1)
   GetWinName = WinTitle$
End Function

Private Sub Command1_Click()
    If Text1.Text = "" Or Text2.Text = "" Then
        MsgBox "输入不全", vbCritical, "提示"
        Exit Sub
    End If
    Timer1.Enabled = True
    Timer1.Interval = Val(Text2.Text) * 500
    Command1.Enabled = False
    Command2.Enabled = True
    Text1.Enabled = False
    Text2.Enabled = False
End Sub

Private Sub Command2_Click()
    Timer1.Enabled = False
    Command1.Enabled = True
    Command2.Enabled = False
    Text1.Enabled = True
    Text2.Enabled = True
End Sub

Private Sub Form_Load()
    Command1.Enabled = True
    Command2.Enabled = False
End Sub

Private Sub Timer1_Timer()
   On Error Resume Next
  
   Call SendInfo(Text1.Text)
End Sub

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值