你运行过程中应该用到了Timer1控制地鼠出现的时间你暂停时把Timer1的Enabled 为 False就可以了。
暂停代码为:
Timer1Enabled = False
继续运行代码为:
Timer1Enabled = True
停止你只需要把开始运行的各种函数值重新赋予初始值就可以了。
调用系统自带的taskkill
call shell("taskkill /im " & "XXXEXE",vbhide)
使用API:
Attribute VB_Name = "killtask"
Option Explicit
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Private Type PROCESSENTRY32
dwSize As Long
cntUsage As Long
th32ProcessID As Long
th32DefaultHeapID As Long
th32ModuleID As Long
cntThreads As Long
th32ParentProcessID As Long
pcPriClassBase As Long
dwFlags As Long
szExeFile As String 1024
End Type
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Dim pid As Long
Dim pname As String
'-------------结束进程通用函数 注意进程名要区分大小写
Private Sub taskkill(ByVal taskname As String)
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim flag As Boolean
Dim mName As String
Dim i As Integer
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
mydwSize = 1060
If (Process32First(l, my)) Then '遍历第一个进程
Do
i = InStr(1, myszExeFile, Chr$(0))
mName = LCase$(Left$(myszExeFile, i - 1))
If mName = LCase$(taskname) Then
pid = myth32ProcessID
pname = mName
Dim mProcID As Long
mProcID = OpenProcess(1&, -1&, pid)
TerminateProcess mProcID, 0&
flag = True
Exit Sub
Else
flag = False
End If
Loop Until (Process32Next(l, my) < 1) '遍历所有进程知道返回值为False
End If
l1 = CloseHandle(l)
End If
End Sub
在程序中调用taskkill即可
call taskkill("XXXEXE")
以上就是关于vb用一个按钮如何做出停止和暂停全部的内容,包括:vb用一个按钮如何做出停止和暂停、如何用vb结束一个程序、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)