Klassennamen von Webbrowsern
02.06.2005 14:52:54
Webbrowsern
ich brauche mal wieder eure Hilfe. Ich benötige für ein Makro, welches mit verschiedenen Webbrowsern zusammenarbeiten soll, den Klassennamen des Browsers. Den von Internet Explorer habe ich, da ich den selbst benutze. Also, einfach den folgenden Code in ein Standardmodul einfügen und laufen lassen. In Spalte A wird der Klassenname, in Spalte B der Fenstertitel ausgegeben. Ich benötige den Klassennamen und den Browsernamen eventuell mit Versionsangabe. Vielen Dank für eure mithilfe im voraus.
Nepumuk
Option Explicit
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal wCmd As Long) As Long
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" ( _
ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Const GW_HWNDFIRST = 0
Private Const GW_HWNDNEXT = 2
Private Const GWL_STYLE = -16
Private Const WS_VISIBLE = &H10000000
Private Const WS_BORDER = &H800000
Private Const MAX_COUNT = 256
Public Sub prcClassName()
Dim intIndex As Integer
Dim lnghWnd As Long, lngStyle As Long, lngReturn As Long
Dim strClassName As String, strTitle As String
strClassName = Space$(MAX_COUNT)
lnghWnd = GetWindow(FindWindow(vbNullString, vbNullString), GW_HWNDFIRST)
Do
lngStyle = GetWindowLong(lnghWnd, GWL_STYLE) And _
(WS_VISIBLE Or WS_BORDER)
If lngStyle = (WS_VISIBLE Or WS_BORDER) Then
lngReturn = GetClassName(lnghWnd, strClassName, MAX_COUNT)
strTitle = Trim$(fncGetWindowTitle(lnghWnd))
intIndex = intIndex + 1
Cells(intIndex, 1).Value = strClassName
Cells(intIndex, 2).Value = strTitle
End If
lnghWnd = GetWindow(lnghWnd, GW_HWNDNEXT)
Loop Until lnghWnd = 0
End Sub
Private Function fncGetWindowTitle(ByVal lnghWnd As Long) As String
Dim lngReturn As Long, strTemp As String
lngReturn = GetWindowTextLength(lnghWnd) + 1
strTemp = Space$(lngReturn)
GetWindowText lnghWnd, strTemp, lngReturn
fncGetWindowTitle = Left$(strTemp, Len(strTemp) - 1)
End Function