Option Explicit
Declare PtrSafe Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As LongPtr, ByVal lpString As String, ByVal cch As Long) As Long
Declare PtrSafe Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As LongPtr) As Long
Declare PtrSafe Function GetWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal wCmd As Long) As LongPtr
Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Const GW_HWNDNEXT As Long = 2
Sub ObtenirNomsFenetres()
Dim hwnd As LongPtr
Dim windowTitle As String
Dim windowTextLength As Long
hwnd = FindWindow(vbNullString, vbNullString)
Do While hwnd <> 0
windowTextLength = GetWindowTextLength(hwnd)
If windowTextLength > 0 Then
windowTitle = Space(windowTextLength + 1)
GetWindowText hwnd, windowTitle , windowTextLength + 1
windowTitle = Left(windowTitle, InStr(windowTitle, Chr(0)) - 1)
MsgBox windowTitle
End If
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
End Sub