對象'HWND'的方法'IWebBrowser1'失敗’

不能直接使用。解決方法如下:
一、新建一個模塊,複製下面代碼:
Option Explicit
Private Const GW_HWNDNEXT = 2
Private Const GW_CHILD = 5
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long

 Function GetWebBrowserHwnd(hwndBrowserContainer As Long) As Long
Dim RetVal As Long
Dim hwndPeer As Long
Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD)
Do While hwndPeer <> 0
RetVal = GetClassName(hwndPeer, ClassString, 256)
If InStr(ClassString, "Shell Embedding") <> 0 Then
GetWebBrowserHwnd = hwndPeer
Exit Do
End If
hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
Loop
End Function
二、在窗體中獲取webbrowser1的hwnd的方法是:
dim i as long
i=GetWebBrowserHwnd(Me.hwnd)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章