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.
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.