Home > How-To Library > System & API

Check & Terminate Process using Window Title

**************************************************************** * © 2007 CodeItBetter http://www.codeitbetter.com * * This notice MUST stay intact for legal use * ****************************************************************
Option Explicit Private Declare Function IsWindow Lib "user32" (ByVal hwnd As Long) As Long Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, _ ByVal nIndex As Long) 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 Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, _ ByVal lpWindowName As String) As Long Private Const GWL_STYLE = -16 Private Const WS_DISABLED = &H8000000 Private Const WM_CLOSE = &H10 Public Function ShutWindow(Window_Title As String) Dim X As Long Dim WindowHwnd As Long WindowHwnd = FindWindow(0&, Window_Title) If WindowHwnd = 0 Then Exit Function If IsWindow(WindowHwnd) = False Then Else If Not (GetWindowLong(WindowHwnd, GWL_STYLE) And WS_DISABLED) Then X = PostMessage(WindowHwnd, WM_CLOSE, 0, 0&) End If End If End Function 'How can I call this Function: Private Sub Command1_Click() ShutWindow "Untitled - Notepad" End Sub

If you would like to submit your code here please us. Do not forget to mention your name. We are always thankful to each and everyone of you who submitted their code here.