Check & Terminate Process using Window Title
Posted on January 4, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 'System & API - Check & Terminate Process using Window Title 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 |
Related posts:
- How to check if a task exists by searching for (part or all of) the window title
- How to get the window title of external application
- How to check the window state of an external application
- How to get the title of the Active Window
- How to get Caption and Thread ID of Window under cursor
- How to terminate an application
- How to bring an external window to top using its caption
- How to Hide/Show the Title bar at Run-Time
- How to find and terminate running applications
- How to close the child windows in an external application.