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:
Option Explicit 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 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function GetExitCodeThread Lib "kernel32" (ByVal hThread As Long, lpExitCode As Long) As Long Private Declare Sub ExitThread Lib "kernel32" (ByVal dwExitCode As Long) Private Sub Command1_Click() 'display asynch message box MessageBoxEx 0&, "Pulchritude" & vbNewLine & "Ansync Messagebox", "Discombobulated", 0&, 0 End Sub Private Sub Command2_Click() 'attempt to close asynch message box Dim hwnd As Long Dim Pid As Long Dim TID As Long Dim lpExitCode As Long Dim hThread As Long hwnd = FindWindow("#32770", "Discombobulated") If hwnd Then TID = GetWindowThreadProcessId(hwnd, Pid) Call GetExitCodeThread(TID, lpExitCode) 'fine to here but now what? End If End Sub





Reply With Quote