UNLOAD 窗体后,如何彻底结束一个窗体
大家都知道,UNLOAD 一个窗体后,还有一部分与之相关的代码和变量没有结束,如何彻底清除这些东西呢? --------------------编程问答-------------------- 先用代码打扫战场,把可能残存的对象设为Nothing,先UNLOAD 窗体,代码都没了,还咋清除?要么干脆End. --------------------编程问答-------------------- 楼上的高 --------------------编程问答--------------------form1_unload()--------------------编程问答-------------------- End是吧整个程序给干掉了吧?而不是某一个窗体。Unload后还有一部分代码和变量没有结束,最好的办法是重组你的代码,把代码写的更合理些最好,不然可能会导致程序出现一些错乱。 --------------------编程问答-------------------- set formx = nothing --------------------编程问答-------------------- 如果你确定要强制关了又怕其他代码起祸端 建立个模块 加入下面代码
set form1=nothing
end sub
Option Explicit
Public 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 * 260
End Type
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Public Const TH32CS_SNAPPROCESS = &H2&
'关闭指定名称的进程
Public Function KillProcess(sProcess As String)
On Error Resume Next
Dim lSnapShot As Long
Dim lNextProcess As Long
Dim tPE As PROCESSENTRY32
lSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&)
If lSnapShot <> -1 Then
tPE.dwSize = Len(tPE)
lNextProcess = Process32First(lSnapShot, tPE)
Do While lNextProcess
If LCase$(sProcess) = LCase$(Left(tPE.szExeFile, InStr(1, tPE.szExeFile, Chr(0)) - 1)) Then '比较进程名
Dim lProcess As Long
Dim lExitCode As Long
lProcess = OpenProcess(1, False, tPE.th32ProcessID)
TerminateProcess lProcess, lExitCode
CloseHandle lProcess
End If
lNextProcess = Process32Next(lSnapShot, tPE)
Loop
CloseHandle (lSnapShot)
End If
End Function
'调用 KillProcess "工程1.exe"
--------------------编程问答-------------------- 合理释放变量就可以释放了。 --------------------编程问答-------------------- 保证这个窗体里的所有函数和过程没有还在运行的。
然后 set form1 = nothing --------------------编程问答-------------------- 把相关的代码贴出来。 --------------------编程问答-------------------- 路过,帮顶. --------------------编程问答-------------------- 放学前要记得打扫卫生 --------------------编程问答-------------------- 卸载窗体,释放内存。二楼的精炼 --------------------编程问答-------------------- 在 Form_Unload() 中释放。 --------------------编程问答-------------------- close --------------------编程问答-------------------- 6楼的代码不错
*****************************************************************************
欢迎使用CSDN论坛专用阅读器 : CSDN Reader(附全部源代码)
http://feiyun0112.cnblogs.com/ --------------------编程问答-------------------- end
补充:VB , 控件