ITeye博客

对象'HWND'的方法'IWebBrowser1'失败’

piperzero · 2012-12-22 12:38 · Markdown

不能直接使用。解决方法如下:
一、新建一个模块,复制下面代码:
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)

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。