How to get the DOM of a WebBrowser control from a window handle (VB6)

转载 2004年09月07日 18:40:00

How to get the DOM of a WebBrowser control from a window handle (VB6)
http://www.mvps.org/emorcillo/en/code/vb6/iedom.shtml

The following code is the VB version of the C code in the KB article 249232 - HOWTO: Get IHTMLDocument2 from a HWND. It requires oleacc.dll to be installed on the system (oleacc.dll is part of the Active Accessibility).

'
' Requires: reference to "Microsoft HTML Object Library"
'

Private Type UUID
   Data1 As Long
   Data2 As Integer
   Data3 As Integer
   Data4(0 To 7) As Byte
End Type

Private Declare Function GetClassName Lib "user32" _
   Alias "GetClassNameA" ( _
   ByVal hWnd As Long, _
   ByVal lpClassName As String, _
   ByVal nMaxCount As Long) As Long

Private Declare Function EnumChildWindows Lib "user32" ( _
   ByVal hWndParent As Long, _
   ByVal lpEnumFunc As Long, _
   lParam As Long) As Long

Private Declare Function RegisterWindowMessage Lib "user32" _
   Alias "RegisterWindowMessageA" ( _
   ByVal lpString As String) As Long

Private 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 Long
      
Private Const SMTO_ABORTIFHUNG = &H2

Private Declare Function ObjectFromLresult Lib "oleacc" ( _
   ByVal lResult As Long, _
   riid As UUID, _
   ByVal wParam As Long, _
   ppvObject As Any) As Long

Private Declare Function FindWindow Lib "user32" _
   Alias "FindWindowA" ( _
   ByVal lpClassName As String, _
   ByVal lpWindowName As String) As Long

'
' IEDOMFromhWnd
'
' Returns the IHTMLDocument interface from a WebBrowser window
'
' hWnd - Window handle of the control
'
Function IEDOMFromhWnd(ByVal hWnd As Long) As IHTMLDocument
Dim IID_IHTMLDocument As UUID
Dim hWndChild As Long
Dim lRes As Long
Dim lMsg As Long
Dim 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 If

End Function

Private Function IsIEServerWindow(ByVal hWnd As Long) As Boolean
Dim lRes As Long
Dim sClassName As String

   ' Initialize the buffer
   sClassName = String$(100, 0)
   
   ' Get the window class name
   lRes = GetClassName(hWnd, sClassName, Len(sClassName))
   sClassName = Left$(sClassName, lRes)
   
   IsIEServerWindow = StrComp(sClassName, _
                      "Internet Explorer_Server", _
                      vbTextCompare) = 0
   
End Function

'
' Copy this function to a .bas module
'
Function EnumChildProc(ByVal hWnd As Long, lParam As Long) As Long
   
   If IsIEServerWindow(hWnd) Then
      lParam = hWnd
   Else
      EnumChildProc = 1
   End If
   
End Function

React框架开发问题总结

react-dom.js:18962 Warning: Unknown prop `col` on  tag. Remove this prop from the element. For detai...
  • itpinpai
  • itpinpai
  • 2016年11月23日 16:42
  • 6575

github在eclipse上的插件egit官方使用指南

转自:http://wiki.eclipse.org/EGit/User_Guide EGit/User Guide EGit Contents  [h...
  • shanliangliuxing
  • shanliangliuxing
  • 2013年02月04日 16:10
  • 20337

Solr入门之官方文档6.0阅读笔记系列(十)

The Well-Configured Solr Instance 告诉你如何调节solr实例到最佳性能 Configuring solrconfig.xml solrcon...
  • sqh201030412
  • sqh201030412
  • 2016年09月06日 17:03
  • 2989

如何掌控自己的时间和生活].How.to.Get.Control.of.Your.Time.and.Your.Life.2006.Scan.CHS-INTERNET.pdf

  • 2009年12月17日 10:37
  • 26.3MB
  • 下载

《How to Get Control of Your Time and Your Life》

Chapter 1 为何要掌控时间?改掉拖拉习惯,高效工作,改变自己的生活 Chapter 2 掌控生活,必有回报掌控时间,聪明工作,不做“时间狂”,有时间去完成之前因为“没有时间”而一直推迟的梦想 ...
  • fgszdgbzdb
  • fgszdgbzdb
  • 2017年07月08日 10:55
  • 230

How to get an X11 Window from a Process ID?

http://stackoverflow.com/questions/151407/how-to-get-an-x11-window-from-a-process-id Under Linu...
  • echoisland
  • echoisland
  • 2011年12月20日 21:31
  • 898

How to get control of your time and your life

How to get control of your time and your life1.         I count ALL my time as important time and tr...
  • QIBAOYUAN
  • QIBAOYUAN
  • 2011年02月12日 16:15
  • 598

Get a window’s handle from the current cursor position.

  • 2006年02月23日 09:05
  • 5KB
  • 下载

How to get the Values of Selected Row from a Gridview using ASP.NET

In this Article you can learn how to get the values of selected row from a Gridview and display the ...
  • L_Vincent
  • L_Vincent
  • 2011年08月29日 14:40
  • 639

How to get the visible region of a window or CDC(转自http://www.programmersheaven.com)

If one is dealing with an application that performs a lot of painting or drawing, the OnDraw functio...
  • heiantianshi1
  • heiantianshi1
  • 2011年05月20日 22:52
  • 919
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:How to get the DOM of a WebBrowser control from a window handle (VB6)
举报原因:
原因补充:

(最多只允许输入30个字)