Dim threadid1 As Long
Call CreateThread(Null, ByVal O&, AddressOf Module1.zhuce, VarPtr(0), ByVal 0&, threadid1)我用次方法建立了一个进程,可是在退出程序的时候,vb环境都退出来了!
有什摸方法关掉次进程???

解决方案 »

  1.   

    set threadid1 = Nothing
      

  2.   

    Public Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As LongCall TerminateThread(threadid1, 0)'关闭进程
      

  3.   

    ' 新建一个工程,然后添加一个模块,并设启动窗口为 Sub Main()Option ExplicitPrivate Declare Function CreateThread Lib "kernel32" ( _
        lpThreadAttributes As Any, _
        ByVal dwStackSize As Long, _
        ByVal lpStartAddress As Long, _
        lpParameter As Any, _
        ByVal dwCreationFlags As Long, _
        lpThreadId As Long) As LongPrivate Declare Function TerminateThread Lib "kernel32" ( _
        ByVal hThread As Long, _
        ByVal dwExitCode As Long) As LongPrivate Sub Main()
        Dim hThread As Long
        Dim dwExitCode As Long
        
        CreateThread ByVal 0, 0, AddressOf PrintError, 1, 0, hThread
        
        If hThread <> 0 Then
            TerminateThread hThread, dwExitCode
        End If
    End SubPublic Function PrintError(ByVal lpData As Long) As Long
        MsgBox lpData
    End Function
      

  4.   

    注意 CreateThread 的参数传值方式我改了一下,使用时切需注意。
      

  5.   

    MSDN 6.0 也有相关的 VB 示例,请见 MSDN 的这一页:mk:@MSITStore:C:\Program%20Files\Microsoft%20Visual%20Studio\MSDN98\98VS\2052\period97.chm::/periodic/msj/thread897.htm
      

  6.   

    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 LongPrivate 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 TypeConst TH32CS_SNAPPROCESS = &H2Dim my As PROCESSENTRY32Private Sub Form_Load()Dim str As String
    Dim l As Long
    Dim l1 As Long    l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
      
        If l Then
            my.dwSize = 1060
        
            If (Process32First(l, my)) Then
                Do Until (Process32Next(l, my) < 1)
                    MsgBox my.szExeFile
                Loop
            End If
        
        l1 = CloseHandle(l)
      End If
      
    End Sub