窗体上加三个按钮
Option Explicit
Private Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
ByVal lParam 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" _
Alias "SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Const WM_CLOSE = &H10
Private Target As String
Private Function closewin(ByVal app_hwnd As Long, _
ByVal param As Long) As Long
Dim buf As String * 256
Dim title As String
Dim length As Long
length = GetWindowText(app_hwnd, buf, Len(buf))
title = Left(buf, length)
If InStr(title, Target) <> 0 Then
SendMessage app_hwnd, WM_CLOSE, 0, 0
End If
closewin = True
End Function
Public Sub pausetask(app_name As String)
Target = app_name
EnumWindows AddressOf closewin, 0
End Sub
Private Sub Command1_Click()
Dim x
x = Shell("calc.exe")
End Sub
Private Sub Command2_Click()
pausetask "¼ÆËãÆ÷"
End Sub
Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
Command1.Caption = "´ò¿ª¼ÆËãÆ÷"
Command2.Caption = "¹Ø±Õ¼ÆËãÆ÷"
Command3.Caption = "Í˳ö"
Me.Caption = "»Øµ÷º¯ÊýÑÝʾ"
End Sub