Obtaining the hWnd for the WebBrowser control

‘Obtaining the hWnd for the WebBrowser control

Add this code to a Module:

Option Explicit

Public Const GW_CHILD = 5
Public Declare Function GetWindow Lib “user32” (ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Public 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 Result As Long
Dim hwndChild As Long
Dim hwnd As Long
Dim ClassString As String * 256

hwnd = hwndBrowserContainer
hwndChild = hwnd

While (Result = 0) And (hwndChild <> 0)
hwndChild = GetWindow(hwnd, GW_CHILD)
If hwndChild <> 0 Then
hwnd = hwndChild
RetVal = GetClassName(hwnd, ClassString, 256)
If Left$(ClassString, InStr(ClassString, Chr$(0)) – 1) = _
“HTML_Internet Explorer” Then
Result = 1
End If
End If

GetBrowserWindow = hwnd

End Function


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s