VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Close Any Application

by Alex (11 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (7 Votes)

This code will Close any application based on its windows caption

API Declarations
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10

Rate Close Any Application


Public Function CloseApplication(byVal sAppCaption As String) As Boolean
  Dim lHwnd As Long
  Dim lRetVal As Long
  
  lHwnd = FindWindow(vbNullString, sAppCaption)
  If lHwnd <> 0 Then
    lRetVal = PostMessage(lHwnd, WM_CLOSE, 0&, 0&)
  End If
End Function

Download this snippet    Add to My Saved Code

Close Any Application Comments

No comments have been posted about Close Any Application. Why not be the first to post a comment about Close Any Application.

Post your comment

Subject:
Message:
0/1000 characters