当前位置:编程学习 > VB >>

webbrowser对象怎么取得hwnd

用shellwindows获取的webbrowser对象,用hwnd方法出现自动化错误,如何取得对象的句柄,用API实现 --------------------编程问答-------------------- Option Explicit
   Public Const GW_HWNDNEXT = 2
   Public 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





Public 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)
    Do While hwndPeer <> 0
        
        RetVal = GetClassName(hwndPeer, ClassString, 256)
        If InStr(ClassString, "Shell Embedding") <> 0 Then
            Exit Do
        End If
        hwndPeer = GetWindow(hwndPeer, GW_HWNDNEXT)
    Loop
    GetBrowserwindow = hwndPeer
End Function
--------------------编程问答--------------------
引用 1 楼  的回复:
Option Explicit
   Public Const GW_HWNDNEXT = 2
   Public Const GW_CHILD = 5
   Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
   Private Declare……

这个方法早就知道了,不好用,webbrowser的hwnd都没有怎么得到容器的hwnd,看看有没有什么好用的方法,比如让oject直接返回句柄的函数之类的 --------------------编程问答-------------------- 我一般采用FindWindow来获取窗口的句柄,然后使用FindWindowEx来获取窗口内子控件的句柄,一一枚举出来即可。 --------------------编程问答-------------------- 找了英文网站也没有找到方法,已经控制object获取句柄就这么难?webbrowser为什么又不支持hwnd属性?看来这个问题算是不了了之了 --------------------编程问答-------------------- 用IOleWindow的GetWindow应该也是可以的 --------------------编程问答-------------------- GetBrowserwindow(webbrowser.parent.hwnd)可以么?
这个browser是你自己的程序里的? --------------------编程问答-------------------- 方法是有的,比较麻烦,像是IE8 多标签的更复杂,要是IE6这种的简单点,先找到shellwindows对应的IE窗口句柄,再一层一层往下找到WEB控件的句柄就行了,类名是Internet Explorer_Server,
多标签的就不知是哪一个了,这才是技术问题,因为有多个Internet Explorer_Server
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,