Получение списка запущенных окон и закрытие выбранного окна из списка
Вставьте в форму вот это.
Добавь на форму cmdClose - кнопку и lstList - ЛистБокс.
Теперь ты не только видишь все приложения и их окна но и можешь их закрывать - осторожнее - не все закрываються корректно :)
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
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 cmdClose_Click()
hW = FindWindow(vbNullString, lstList.Text & Chr(0))
PostMessage hW, WM_QUIT, 0, 0
End Sub
Private Sub Form_Load()
Left = (Screen.Width - Width) \ 2
Top = (Screen.Height - Height) \ 2
GetTaskList
End Sub
|
|