Csharp
05-13-2003, 06:47 PM
hi dudes, i put a little bit of code together which enables you to get a webbrowser's hWnd with great ease ( no subclassing etc... )
Option Explicit
'///GETTING A WEBBROWSER'S HWND THE REALLY EASY WAY. _
'////BY DYNAMIC SYSOP.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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 Form_Load()
WebBrowser1.Navigate "http://chat.msn.com"
End Sub
Private Sub WebBrowser1_DownloadComplete()
Dim l As Long, sl As Long
Dim strin As String * 256
l = FindWindowEx(Form1.hWnd, ByVal 0&, "Shell Embedding", vbNullString)
l = FindWindowEx(l, ByVal 0&, "Shell DocObject View", vbNullString)
l = FindWindowEx(l, ByVal 0&, "Internet Explorer_Server", vbNullString)
sl = GetClassName(l, strin, 256) '/// l is the hWnd of the browser.
Caption = strin '// set the form's caption to the classname of the browser
'///IF YOU WAIT TILL THE BROWSER HAS NAVIGATED AND THEN USE THE ABOVE _
'///YOU WILL RECEIVE THE HANDLE OF THE WEBBROWSER. _
'///OR IF YOU DONT WANT IT IN THIS AREA, FIRST ALLOW THE BROWSER TO NAVIGATE _
'///THEN ADD IN A SUB ( EG: COMMAND_CLICK )
End Sub
this saves having to use enumchildwindows or other hooks :)
Option Explicit
'///GETTING A WEBBROWSER'S HWND THE REALLY EASY WAY. _
'////BY DYNAMIC SYSOP.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) 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 Form_Load()
WebBrowser1.Navigate "http://chat.msn.com"
End Sub
Private Sub WebBrowser1_DownloadComplete()
Dim l As Long, sl As Long
Dim strin As String * 256
l = FindWindowEx(Form1.hWnd, ByVal 0&, "Shell Embedding", vbNullString)
l = FindWindowEx(l, ByVal 0&, "Shell DocObject View", vbNullString)
l = FindWindowEx(l, ByVal 0&, "Internet Explorer_Server", vbNullString)
sl = GetClassName(l, strin, 256) '/// l is the hWnd of the browser.
Caption = strin '// set the form's caption to the classname of the browser
'///IF YOU WAIT TILL THE BROWSER HAS NAVIGATED AND THEN USE THE ABOVE _
'///YOU WILL RECEIVE THE HANDLE OF THE WEBBROWSER. _
'///OR IF YOU DONT WANT IT IN THIS AREA, FIRST ALLOW THE BROWSER TO NAVIGATE _
'///THEN ADD IN A SUB ( EG: COMMAND_CLICK )
End Sub
this saves having to use enumchildwindows or other hooks :)