VB一个问题

来源:百度知道 编辑:UC知道 时间:2024/06/25 00:04:05
我想在VB设置监控某个程序 当某个程序出现被检测到就自动关闭
怎么做

Form1 代码:
要求 Timer1, 将Interval设为:1000,Timer2,将 Interval设为 5000 或 10000, List1

Option Explicit

Private Const prc_list = "notepad.exe realplay.exe" ''这里是要想监视的进程,以空格分隔

Private Sub Form_Load()
Dim ret As Long

preWinProc = GetWindowLong(Me.hwnd, GWL_WNDPROC)
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, AddressOf wndproc)
idHotKey = 1 'in the range &h0000 through &hBFFF
Modifiers = MOD_CONTROL
uVirtKey = vbKeyQ
ret = RegisterHotKey(Me.hwnd, idHotKey, Modifiers, uVirtKey)
me.hide
WriteRun
End Sub

Private Sub Form_Resize()
If Me.WindowState = 1 Then
Me.Hide
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Dim ret As Long
'取消Message的截取,而使之又只送往原来的Window Procedure
ret = SetWindowLong(Me.hwnd, GWL_WNDPROC, preWinProc)
Call UnregisterHotKey(Me.hwnd, uVirtKey)
End Sub

Pr