soundex2 » 17.03.2003 (Пн) 11:20
'Эт называется Нахождение hwnd чужих окон
'Тут всё ясно и просто........давно прошедшая и забытая тема
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd 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 GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const WM_CLOSE = &H10
Const WM_QUIT = &H12
Dim CurrWnd As String
Dim ListItem As String
Dim Length As String
Dim hW As Long
Sub GetTaskList()
CurrWnd = GetWindow(Me.hwnd, GW_HWNDFIRST)
Do While CurrWnd <> 0
Length = GetWindowTextLength(CurrWnd)
ListItem = Space(Length + 1)
Length = GetWindowText(CurrWnd, ListItem, Length + 1)
If Length <> 0 Then
lstList.AddItem ListItem
End If
CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
DoEvents
Loop
End Sub
Private Sub Command1_Click()
GetTaskList
End Sub
Private Sub Command2_Click()
lstList.Clear
GetTaskList
End Sub
Private Sub Command3_Click()
hW = FindWindow(vbNullString, lstList.Text & Chr(0))
PostMessage hW, WM_QUIT, 0, 0
End Sub