在vb中,用于结束整个程序运行的辅助控制语句是

在vb中,用于结束整个程序运行的辅助控制语句是,第1张

用vb控制其他窗体的显示状态(api):

先用findwindow获取那个窗体的句柄,再用showwindow控制窗体的显示状态,0为隐藏,1为显示

具体代码请百度一下

LSD,请不要给布尔型变量赋 数值

False = 0

True = -1

================================

一般而言,用一个Boolean变量来保存过程是否要继续执行

TRUE表示继续,FLASE表示终止

但在一个过程运行时,VB就像死了一样,无法进行其他 *** 作,所以VB提供了一个函数

DoEvents()

使程序在处理一个过程的同时,还能进行其他 *** 作。

Dim Doing As Boolean

Private Sub Command1_Click()

Doing = False

End Sub

Private Sub Command2_Click()

DoEvents

If Not Doing Then Exit Sub

'//Add code 1 here

If Not Doing Then Exit Sub

'//Add code 2 here

'//

End Sub

调用系统自带的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")

ctrl+break或ctrl+c,有时要多按几下,然后结束所运行的程序保存即可。另copy外,建议你点击菜单工具--选项,选择环境选项卡,选中“启动程序时”“提示保存改变”,这样可zhidao以提醒你在运行前保存程序。

以上就是关于在vb中,用于结束整个程序运行的辅助控制语句是全部的内容,包括:在vb中,用于结束整个程序运行的辅助控制语句是、vb中怎样通过命令按钮结束一个过程、如何用vb结束一个程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9277182.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-26
下一篇 2023-04-26

发表评论

登录后才能评论

评论列表(0条)

保存