|
用API的方法如下:- Private Declare Function SetFocusAPI& Lib "user32" Alias "SetFocus" (ByVal hwnd As Long)
- Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
- Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
- Dim mpID As Long
- Private Sub Text2_GotFocus()
- On Error Resume Next
- mpID = Shell(CurrentProject.Path & "\SoftBoard.exe", 1)
- DoEvents
- SetFocusAPI Me.hwnd
- End Sub
- Private Sub Text2_LostFocus()
- Dim hP As Long
- If mpID <> 0 Then
- hP = OpenProcess(1&, -1&, mpID)
- If TerminateProcess(hP, 1) <> 0 Then mpID = 0 '强制关闭程序
- End If
- End Sub
复制代码 |
|