Auflisten aller geöffneten Officeprogrammen
03.08.2021 17:47:39
Nepumuk
Hallo Pepi,
so ok?
Option Explicit
Private Declare PtrSafe Function EnumWindows Lib "user32.dll" ( _
ByVal lpEnumFunc As LongPtr, _
ByVal lParam As LongPtr) As Long
Private Declare PtrSafe Function GetWindowTextA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal lpString As String, _
ByVal cch As Long) As Long
Private Declare PtrSafe Function GetWindowTextLengthA Lib "user32.dll" ( _
ByVal hwnd As LongPtr) As Long
Private Declare PtrSafe Function GetClassNameA Lib "user32.dll" ( _
ByVal hwnd As LongPtr, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, _
ByVal nIndex As Long) As LongPtr
Private Const GWL_STYLE As Long = -16&
Private Const WS_VISIBLE As Long = &H10000000
Private Const WS_BORDER As Long = &H800000
Private Const MAX_CLASS_NAME As Long = 255
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 pvlngptrHwnd As LongPtr, ByVal lngptrParam As LongPtr) As LongPtr
Dim strCaption As String, strClassName As String
Dim lngReturn As Long
Dim lngptrStyle As LongPtr
lngptrStyle = GetWindowLong(pvlngptrHwnd, GWL_STYLE)
If (lngptrStyle And (WS_VISIBLE Or WS_BORDER)) = (WS_VISIBLE Or WS_BORDER) Then
strClassName = Space$(MAX_CLASS_NAME)
lngReturn = GetClassNameA(pvlngptrHwnd, strClassName, MAX_CLASS_NAME)
strClassName = Left$(strClassName, lngReturn)
lngReturn = GetWindowTextLengthA(pvlngptrHwnd)
strCaption = Space$(lngReturn)
Call GetWindowTextA(pvlngptrHwnd, strCaption, lngReturn + 1)
llngRow = llngRow + 1
Cells(llngRow, 1).Resize(1, 3) = Array(pvlngptrHwnd, strClassName, strCaption)
End If
WindowCallBack = 1
End Function
Gruß
Nepumuk