hi
i have the following code
i want to add for each in this code but i don't know how.
i want for each application that is fined the code will be run. can you help me please?
Function fCloseApp(pClassName As String) As Boolean
'Usage Examples:
' To close Calculator:
' ?fCloseApp("SciCalc")
'
Dim lngRet As Long, Hwnd As Long, pID As Long
Hwnd = apiFindWindow(pClassName, vbNullString)
If (Hwnd) Then
lngRet = apiPostMessage(Hwnd, WM_CLOSE, 0, ByVal 0&)
Call apiGetWindowThreadProcessId(Hwnd, pID)
Call apiWaitForSingleObject(pID, INFINITE)
fCloseApp = Not (apiIsWindow(Hwnd) = 0)
End If
End Function
the rest of the code is below:
thank you
i have the following code
i want to add for each in this code but i don't know how.
i want for each application that is fined the code will be run. can you help me please?
Function fCloseApp(pClassName As String) As Boolean
'Usage Examples:
' To close Calculator:
' ?fCloseApp("SciCalc")
'
Dim lngRet As Long, Hwnd As Long, pID As Long
Hwnd = apiFindWindow(pClassName, vbNullString)
If (Hwnd) Then
lngRet = apiPostMessage(Hwnd, WM_CLOSE, 0, ByVal 0&)
Call apiGetWindowThreadProcessId(Hwnd, pID)
Call apiWaitForSingleObject(pID, INFINITE)
fCloseApp = Not (apiIsWindow(Hwnd) = 0)
End If
End Function
the rest of the code is below:
Code:
Private Const WM_CLOSE = &H10
Private Const INFINITE = &HFFFFFFFF
Private Declare Function apiPostMessage _
Lib "user32" Alias "PostMessageA" _
(ByVal Hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) _
As Long
Private Declare Function apiFindWindow _
Lib "user32" Alias "FindWindowA" _
(ByVal lpClassname As String, _
ByVal lpWindowName As String) _
As Long
Private Declare Function apiWaitForSingleObject _
Lib "kernel32" Alias "WaitForSingleObject" _
(ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) _
As Long
Private Declare Function apiIsWindow _
Lib "user32" Alias "IsWindow" _
(ByVal Hwnd As Long) _
As Long
Private Declare Function apiGetWindowThreadProcessId _
Lib "user32" Alias "GetWindowThreadProcessId" _
(ByVal Hwnd As Long, _
lpdwProcessID As Long) _
As Long
thank you