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 htmldocument 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 lresten
'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) ThenLParam = hwnd
Else
EnumChildProc = 1
END IF
END FUNCTION