发布网友 发布时间:2024-04-02 18:48
共1个回答
热心网友 时间:2024-08-06 04:39
以下代码在360浏览器下调试成功。分两步:一、把下面代码复制到一个模块中:Option ExplicitDeclare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As LongPublic Declare Function SetCapture Lib "user32" (ByVal hWnd As Long) As LongPublic Declare Function GetCursorPos Lib "user32" (lpPoint As PointAPI) As LongPublic Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As LongPublic Declare Function ScreenToClient Lib "user32" (ByVal hWnd As Long, lpPoint As PointAPI) As LongType PointAPI x As Long Y As LongEnd TypePrivate Type UUID Data1 As Long Data2 As Integer Data3 As Integer Data4(0 To 7) As ByteEnd TypePrivate Declare Function GetClassName Lib "user32" _ Alias "GetClassNameA" ( _ ByVal hWnd As Long, _ ByVal lpClassName As String, _ ByVal nMaxCount As Long) As LongPrivate Declare Function EnumChildWindows Lib "user32" ( _ ByVal hWndParent As Long, _ ByVal lpEnumFunc As Long, _ lParam As Long) As LongPrivate Declare Function RegisterWindowMessage Lib "user32" _ Alias "RegisterWindowMessageA" ( _ ByVal lpString As String) As LongPrivate Declare Function SendMessageTimeout Lib "user32" _ Alias "SendMessageTimeoutA" ( _ ByVal hWnd As Long, _ ByVal msg As Long, _ ByVal wParam As Long, _ lParam As Any, _ ByVal fuFlags As Long, _ ByVal uTimeout As Long, _ lpdwResult As Long) As LongPrivate Const SMTO_ABORTIFHUNG = &H2Private Declare Function ObjectFromLresult Lib "oleacc" ( _ ByVal lResult As Long, _ riid As UUID, _ ByVal wParam As Long, _ ppvObject As Any) As LongPrivate Declare Function FindWindow Lib "user32" _ Alias "FindWindowA" ( _ ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long'Function IEDOMFromhWnd(ByVal hWnd As Long) As IHTMLDocumentDim IID_IHTMLDocument As UUIDDim hWndChild As LongDim lRes As LongDim lMsg As LongDim hr As Long If hWnd <> 0 Then If Not IsIEServerWindow(hWnd) Then ' Find a child IE server window EnumChildWindows hWnd, AddressOf EnumChildProc, hWnd End If If hWnd <> 0 Then ' Register the message lMsg = RegisterWindowMessage("WM_HTML_GETOBJECT") ' Get the object pointer Call SendMessageTimeout(hWnd, lMsg, 0, 0, _ SMTO_ABORTIFHUNG, 1000, lRes) If lRes Then ' Initialize the interface ID With IID_IHTMLDocument .Data1 = &H626FC520 .Data2 = &HA41E .Data3 = &H11CF .Data4(0) = &HA7 .Data4(1) = &H31 .Data4(2) = &H0 .Data4(3) = &HA0 .Data4(4) = &HC9 .Data4(5) = &H8 .Data4(6) = &H26 .Data4(7) = &H37 End With ' Get the object from lRes hr = ObjectFromLresult(lRes, IID_IHTMLDocument, _ 0, IEDOMFromhWnd) End If End If End IfEnd FunctionPrivate Function IsIEServerWindow(ByVal hWnd As Long) As BooleanDim lRes As LongDim sClassname As String sClassname = String$(100, 0) lRes = GetClassName(hWnd, sClassname, Len(sClassname)) sClassname = Left$(sClassname, lRes) IsIEServerWindow = StrComp(sClassname, _ "Internet Explorer_Server", _ vbTextCompare) = 0End Function'Function EnumChildProc(ByVal hWnd As Long, lParam As Long) As Long If IsIEServerWindow(hWnd) Then lParam = hWnd Else EnumChildProc = 1 End IfEnd Function二、建立一个窗体,加入按钮command1,并复制下面代码:Private Sub Command1_Click()Dim doc, wnd As Longwnd = FindWindow("360se5_Frame", vbNullString)wnd = FindWindowEx(wnd, 0, "SeWnd", vbNullString)wnd = FindWindowEx(wnd, 0, "XWnd", vbNullString)wnd = FindWindowEx(wnd, 0, "Container", vbNullString)wnd = FindWindowEx(wnd, 0, "Shell Embedding", vbNullString)wnd = FindWindowEx(wnd, 0, "Shell DocObject View", vbNullString)wnd = FindWindowEx(wnd, 0, "Internet Explorer_Server", vbNullString)Set doc = IEDOMFromhWnd(wnd)MsgBox "360浏览器当前的网址是:" & doc.URLEnd Sub三、打开360浏览器,随便浏览某个网址。然后运行本程序,点击command1按钮,Ok!