Dim MyClient As WebClient = New WebClient
Dim MyReader As New System.IO.StreamReader(MyClient.OpenRead(url), System.Text.Encoding.Default) '定义新的文件流并读取网页文件数据,url表示需要打开的网页地址
Dim longTxt As String = MyReader.ReadToEnd 'longtxt存储了网页的源码
MyReader.Close()
Private Function GetCode(ByVal _URL As String) As String
Try
Dim req As HttpWebRequest = WebRequest.Create(_URL)
Dim res As HttpWebResponse = req.GetResponse()
Dim strm As StreamReader = New StreamReader(res.GetResponseStream(), Encoding.Default)
Return strm.ReadToEnd
Catch ex As Exception
Return ""
End Try
End Function
Option Explicit
Private Declare Function GetForegroundWindow Lib "user32" () As Long
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_HWNDNEXT = 2
Private Sub Command1_Click()
Dim hwnd As Long
Dim l As Long
Dim s As String
hwnd = GetForegroundWindow()
While hwnd <> 0
l = GetWindowTextLength(hwnd)
s = String(l + 1, Chr(0))
GetWindowText hwnd, s, l + 1
Print s
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Wend
End Sub