Hallo,
damit habe ich mich auch länger herumgeschlagen, bis ich bei AVB die Lösung gefunden habe, das funktioniert nur noch mit SendMessge, die anderen Programme haben nur bis Win98 funktioniert.
Ich habe mir das Beispiel von AVB etwas umgeschrieben und verkürzt. Ich denke meine Variante ist verständlicher …
Auf der Form liegen
zwei Textfelder: Text1 und Text2
zwei Listen: List1 und List2
zwei Button: Command1 und Command2
Option Explicit
Private Declare Function GetWindow Lib "user32" (ByVal hwnd \_
As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" \_
Alias "GetWindowTextLengthA" (ByVal hwnd As Long) \_
As Long
Private Declare Function GetWindowText Lib "user32" Alias \_
"GetWindowTextA" (ByVal hwnd As Long, ByVal lpString \_
As String, ByVal cch As Long) As Long
Private Declare Function SendMessage Lib "user32.dll" Alias \_
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, \_
ByVal wParam As Long, lParam As Any) As Long
Const GW\_HWNDFIRST = 0
Const GW\_HWNDNEXT = 2
Const WM\_CLOSE = &H10
Private Sub Command1\_Click()
Call EnumWindows
End Sub
Private Sub EnumWindows()
Dim hwnd&, Result&, Title$
List1.Clear
hwnd = GetWindow(Me.hwnd, GW\_HWNDFIRST)
Do
Result = GetWindowTextLength(hwnd) + 1
Title = Space$(Result)
Result = GetWindowText(hwnd, Title, Result)
Title = Left$(Title, Len(Title) - 1)
If Trim(Title) "" Then
List1.AddItem Title
List1.ItemData(List1.NewIndex) = hwnd
End If
hwnd = GetWindow(hwnd, GW\_HWNDNEXT)
Loop Until hwnd = 0
If List1.ListCount \> 0 Then
Command2.Enabled = True
Else
Command2.Enabled = False
End If
End Sub
Private Sub Command2\_Click()
Dim hwnd&
hwnd = Val(Text2.Text)
SendMessage hwnd, WM\_CLOSE, ByVal 0&, ByVal 0&
Command2.Enabled = False
End Sub
Private Sub Form\_Load()
Command2.Enabled = False
End Sub
Private Sub List1\_Click()
Text1.Text = List1.List(List1.ListIndex)
Text2.Text = List1.ItemData(List1.ListIndex)
End Sub
Gruß, Rainer