Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

terminate process - How ?

Status
Not open for further replies.

windoz255

Technical User
Apr 8, 2003
17
GB
Hi,

Can anyone advise me in how I can use the terminateprocess api instead of the postmessage api.

My reason for wanting to do this is to see the difference in the termination of any window I close. One of the main problems I have been getting is memory leaks with postmessage WM_CLOSE. That is the main reason in why I want to see if the terminate code is better in code.

Below is the code from my project which is currently using postmessage, does anyone have any ideas in how I can use terminateprocess instead of postmessage?

'--------------- Form1 Code -----------------------'

Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_CLOSE = &H10
Private Const WM_QUIT = &H12

Private Sub LoadProcesses()
Call EnumWindows(AddressOf EnumWinProc, 0)
End Sub

Private Sub Form_Load()
LoadProcesses
End Sub

Private Sub List1_Click()
Dim CloseIt As Long
CloseIt = FindWindow(vbNullString, List1.List(List1.ListIndex))
PostMessage CloseIt, WM_CLOSE, CLng(0), CLng(0)
List1.Clear
LoadProcesses
End Sub


'-------------------- Module Code --------------'

Option Explicit

Public Declare Function IsWindowVisible Lib "user32" (ByVal hwnd As Long) As Long
Public Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Public Const MAX_LEN = 260
Public Function EnumWinProc(ByVal hwnd As Long, ByVal lParam As Long) As Long
Dim lRet As Long
Dim strBuffer As String

If IsWindowVisible(hwnd) Then
strBuffer = Space(MAX_LEN)
lRet = GetWindowText(hwnd, strBuffer, Len(strBuffer))
If lRet Then
frmProcesses.List1.AddItem Left(strBuffer & " " & hwnd, lRet)
End If
End If

EnumWinProc = 1
End Function

Any advice is appreciated.

Thanks.
 
bbolte,

Thanks for the reply, but the information at the URL seems to do the same thing as my current project.

What I want to do is use the terminateprocess within my given source, rather than using postmessage.


Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long


Any other ideas ?
 
poke around here. they have lots of example and an extremely useful tool called the API Guide... hth
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top