VC 如何获取WebBrowser控件里面网页句柄 10
我做了一个程序,WebBrowser控件里访问了一个网页,我现在想获取WebBrowser控件的句柄,和里面显示的网页的句柄,应该如何操作,我只有这点分了,先谢谢了...
我做了一个程序,WebBrowser控件里访问了一个网页,我现在想获取WebBrowser控件的句柄,和里面显示的网页的句柄,应该如何操作,我只有这点分了,先谢谢了
展开
1个回答
展开全部
能获得所有webbrowser的句柄,但是不知道哪个哪个
添加一个list ,一个command,多个webbrowser
加入以下代码
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
Private Sub Command1_Click()
GetBrowserWindow Me.hwnd
End Sub
Private Function GetBrowserWindow(hwndBrowserContainer As Long) As Long
Dim RetVal As Long
Dim hwndPeer As Long
Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD)
RetVal = GetClassName(hwndPeer, ClassString, 256)
If InStr(ClassString, "Shell Embedding") <> 0 Then
List1.AddItem Str(hwndPeer) & "|" & ClassString
End If
Do While hwndPeer <> 0
hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
RetVal = GetClassName(hwndPeer, ClassString, 256)
If InStr(ClassString, "Shell Embedding") <> 0 Then
List1.AddItem Str(hwndPeer) & "|" & ClassString
End If
Loop
GetBrowserWindow = hwndPeer
End Function
是不是变成Internet Explorer了?
下边这个是获取所有控件的ID和类名:
Private Function GetBrowserWindow(hwndBrowserContainer As Long) As Long
Dim RetVal As Long
Dim hwndPeer As Long
Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD)
RetVal = GetClassName(hwndPeer, ClassString, 256)
List1.AddItem Str(hwndPeer) & "|" & ClassString
Do While hwndPeer <> 0
hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
RetVal = GetClassName(hwndPeer, ClassString, 256)
List1.AddItem Str(hwndPeer) & "|" & ClassString
Loop
GetBrowserWindow = hwndPeer
End Function
我只能帮你这么多了,我也试图通过句柄来获取控件的名称,但还是找不到
添加一个list ,一个command,多个webbrowser
加入以下代码
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
Private Sub Command1_Click()
GetBrowserWindow Me.hwnd
End Sub
Private Function GetBrowserWindow(hwndBrowserContainer As Long) As Long
Dim RetVal As Long
Dim hwndPeer As Long
Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD)
RetVal = GetClassName(hwndPeer, ClassString, 256)
If InStr(ClassString, "Shell Embedding") <> 0 Then
List1.AddItem Str(hwndPeer) & "|" & ClassString
End If
Do While hwndPeer <> 0
hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
RetVal = GetClassName(hwndPeer, ClassString, 256)
If InStr(ClassString, "Shell Embedding") <> 0 Then
List1.AddItem Str(hwndPeer) & "|" & ClassString
End If
Loop
GetBrowserWindow = hwndPeer
End Function
是不是变成Internet Explorer了?
下边这个是获取所有控件的ID和类名:
Private Function GetBrowserWindow(hwndBrowserContainer As Long) As Long
Dim RetVal As Long
Dim hwndPeer As Long
Dim ClassString As String * 256
hwndPeer = GetWindow(hwndBrowserContainer, GW_CHILD)
RetVal = GetClassName(hwndPeer, ClassString, 256)
List1.AddItem Str(hwndPeer) & "|" & ClassString
Do While hwndPeer <> 0
hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
RetVal = GetClassName(hwndPeer, ClassString, 256)
List1.AddItem Str(hwndPeer) & "|" & ClassString
Loop
GetBrowserWindow = hwndPeer
End Function
我只能帮你这么多了,我也试图通过句柄来获取控件的名称,但还是找不到
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询