AW: VBA: Maus bewegen und klicken
28.10.2017 12:02:02
Nepumuk
Hallo Barbara,
öffne das Fenster der Anwendung die du per API manipulieren willst und lass dann folgenden Code laufen. So findest du den Klassennamen.
Option Explicit
Private Declare Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Boolean
Private Declare Function GetWindowTextA Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare Function GetWindowTextLengthA Lib "user32.dll" ( _
ByVal hwnd As Long) As Long
Private Declare Function GetClassNameA Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare Function GetWindowLongA Lib "user32.dll" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Const GWL_STYLE As Long = -16
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_BORDER As Long = &H800000
Private llngRow As Long
Public Sub Start()
llngRow = 1
Columns("A:C").ClearContents
With Range("A1:C1")
.Value = Array("Hwnd", "Klasse", "Caption")
.Font.Bold = True
End With
Call EnumWindows(AddressOf WindowCallBack, ByVal 0&)
Columns("A:C").AutoFit
Tabelle1.Sort.SortFields.Clear
Tabelle1.Sort.SortFields.Add Key:=Columns(2)
With Tabelle1.Sort
.SetRange Columns("A:C")
.Header = xlYes
.MatchCase = False
.Apply
End With
End Sub
Private Function WindowCallBack(ByVal lngHwnd As Long, ByVal lngParam As Long) As Long
Dim strCaption As String, strClassName As String
Dim lngReturn As Long, lngStyle As Long
lngStyle = GetWindowLongA(lngHwnd, GWL_STYLE)
If (lngStyle And (WS_VISIBLE Or WS_BORDER)) = (WS_VISIBLE Or WS_BORDER) Then
strClassName = Space$(256)
lngReturn = GetClassNameA(lngHwnd, strClassName, 256)
strClassName = Left$(strClassName, lngReturn)
lngReturn = GetWindowTextLengthA(lngHwnd)
strCaption = Space$(lngReturn)
Call GetWindowTextA(lngHwnd, strCaption, lngReturn + 1)
llngRow = llngRow + 1
Cells(llngRow, 1).Resize(1, 3) = Array(lngHwnd, strClassName, strCaption)
End If
WindowCallBack = 1
End Function
Gruß
Nepumuk