This is another way to close an app. Paste this in to a Module:
Declare Function EnumWindows Lib "user32.dll" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Long
Declare Function GetWindowTextLength Lib "user32.dll" Alias "GetWindowTextLengthA" (ByVal hWnd As Long) As Long
Declare Function GetWindowText Lib "user32.dll" Alias "GetWindowTextA" (ByVal hWnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal Msg As Long, wParam As Any, lParam As Any) As Long
Public Const WM_CLOSE = &H10
Public gAppToClose As String
Public Function EnumWindowsProc(ByVal hWnd As Long, ByVal lParam As Long) As Long
On Error Resume Next
Dim slength As Long, TitleBar As String, retval As Long
Static winnum As Integer
winnum = winnum + 1
slength = GetWindowTextLength(hWnd) + 1
If slength > 1 Then
TitleBar = Space(slength)
retval = GetWindowText(hWnd, TitleBar, slength)
If InStr(TitleBar, gAppToClose ) Then
Call SendMessage(hWnd, WM_CLOSE, 0&, 0&)
End If
End If
EnumWindowsProc = 1
End Function
To close an app. Place this e.g. into the On Click event of a button:
gAppToClose = "Winzip"
Call EnumWindows(AddressOf EnumWindowsProc, 0)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.