Листбокс нужен и кнопка:
Const GW_HWNDFIRST = 0
Const GW_HWNDNEXT = 2
Const WM_CLOSE = &H10
Dim CurrWnd As Long
Dim Length As Long
Dim ListItem As String
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) 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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub GetTaskList()
Dim str As String
ListBox1.Clear
str = ""
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
If InStr(1, str, Trim(ListItem)) Then GoTo lbl_1
ListBox1.AddItem ListItem
str = str & ListItem
End If
lbl_1: CurrWnd = GetWindow(CurrWnd, GW_HWNDNEXT)
Loop
End Sub
Private Sub Form_Load()
GetTaskList
End Sub
Private Sub ExitProcess_Click()
Dim hW As Long
hW = FindWindow(vbNullString, ListBox1.Text & Chr(0))
SendMessage hW, WM_CLOSE, 0, 0
GetTaskList
End Sub
Ответить
|