я делал так:
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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function GetNextWindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wFlag As Long) As Long
Private Declare Function CloseWindow Lib "user32" (ByVal hwnd As Long) As Long
Public Function GetCaption(lhWnd As Long) As String
Dim sA As String, lLen As Long
lLen = GetWindowTextLength(lhWnd)
sA = String(lLen, 0)
Call GetWindowText(lhWnd, sA, lLen + 1)
GetCaption = sA
End Function
Public Function DLHFindWin(frm As Form, WinTitle As String, CaseSensitive As Boolean) As Long
Dim lhWnd As Long, sA As String
lhWnd = frm.hwnd
Do
DoEvents
If lhWnd = 0 Then Exit Do
If CaseSensitive = False Then
sA = LCase(GetCaption(lhWnd))
WinTitle = LCase(WinTitle)
Else
sA = GetCaption(lhWnd)
End If
If InStr(sA, WinTitle) Then
DLHFindWin = lhWnd
Exit Do
Else
DLHFindWin = 0
End If
lhWnd = GetNextWindow(lhWnd, 2)
Loop
End Function
Sub showwinds()
List1.Clear
For i = 1 To 255
If DLHFindWin(Me, Chr(i), False) <> 0 Then
wind = GetCaption(DLHFindWin(Me, Chr(i), False))
For k = 0 To List1.ListCount
If List1.List(k) = wind Then b = True
Next
If b = False Then List1.AddItem wind Else b = False
End If
Next
End Sub
Private Sub Command1_Click()
Call showwinds
End Sub
'а вот так убивать:
Private Sub kill_Click()
hwind = DLHFindWin(Me, List1.List(List1.ListIndex), False)
CloseWindow hwind
End Sub
сорри за объём, главное что работает