|
方法一
說明
記得有某個離線瀏覽軟體,當你發現你想下載的網址時只要開啟他,他會很自動的將現行IE視窗的網址填到程式的位址列,真的是個很貼心的動作,但這個該如何做呢?我是透過尋找視窗Class的方式,一層一層的找到這個位址視窗,程式如下
程式
Option Explicit Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hwnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_GETTEXT = &HD
Public Function GetIEURLString() As String Dim hwnd As Long, sStr As String sStr = Space(255) hwnd = FindWindowEx(0&, 0&, "IEFrame", vbNullString)
hwnd = FindWindowEx(hwnd, 0&, "WorkerA", vbNullString) hwnd = FindWindowEx(hwnd, 0&, "ReBarWindow32", vbNullString) hwnd = FindWindowEx(hwnd, 0&, "ComboBoxEx32", vbNullString)
hwnd = FindWindowEx(hwnd, 0&, "ComboBox", vbNullString) hwnd = FindWindowEx(hwnd, 0&, "Edit", vbNullString) SendMessage hwnd, WM_GETTEXT, Len(sStr), ByVal sStr
GetIEURLString = Left(sStr, InStr(sStr, Chr(0)) - 1) End Function
當你想取得位址時 只要這樣 MsgBox GetIEURLString() 另外這個方法並不適用於Windows 2000
方法二
說明
程式
Private Sub Command1_Click() On Error GoTo command_error With Label1 .Caption = "" .AutoSize = True
.LinkTopic = "IExplore|WWW_GetWindowInfo" .LinkItem = "0xffffffff" .LinkMode = 2
.LinkRequest End With DoEvents
Exit Sub
command_error:
'try the next step on error
Resume Next End Sub
'如果要取得Netscape的網址 只要修改 .LinkTopic = "Netscape|WWW_GetWindowInfo"
文件出處
Honey
整理時間
2001'7,22.
|