Results 1 to 8 of 8

Thread: Terminating a thread

Threaded View

  1. #1

    Thread Starter
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Terminating a thread

    I have used the messagebox api function to create an async message box. Now I want to terminate the thread containing the messagebox without terminating my applicaiton as well.

    I can get the handle of the thread using GetWindowThreadProcessId().

    Now to try to terminate the thread. I presume I need to use OpenThread API, before using TerminateThread. Problem is, I can't find a VB declare statement for this API.

    Here is the link to the MSDN function definition:
    http://msdn.microsoft.com/library/de...thred_8xb8.asp

    Any help with a translation would be appreciated

    Here is what I am trying to do:
    VB Code:
    1. Option Explicit
    2. Private Declare Function MessageBoxEx Lib "user32" Alias "MessageBoxExA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal uType As Long, ByVal wLanguageId As Long) As Long
    3.  
    4. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    5. Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
    6. Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
    7. Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
    8. Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long
    9. Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long)
    10.  
    11.  
    12. Private Sub Command1_Click()
    13. 'display asynch message box
    14.     MessageBoxEx 0&, "Pulchritude" & vbNewLine & "Ansync Messagebox", "Discombobulated", 0&, 0
    15. End Sub
    16.  
    17.  
    18. Private Sub Command2_Click()
    19. 'attempt to close asynch message box
    20. Dim hwnd                As Long
    21. Dim Pid                 As Long
    22. Dim TID                 As Long
    23. Dim lpExitCode          As Long
    24. Dim hThread             As Long
    25.  
    26. hwnd = FindWindow("#32770", "Discombobulated")
    27.  
    28. If hwnd Then
    29.    
    30.     TID = GetWindowThreadProcessId(hwnd, Pid)
    31.     Call GetExitCodeThread(TID, lpExitCode)
    32.     'fine to here but now what?
    33.  
    34. End If
    35. End Sub
    Last edited by Nucleus; Oct 24th, 2001 at 01:06 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width