CodeItBetter Programming Another VB Programming Blog

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:

  1. How to check if a task exists by searching for (part or all of) the window title
  2. How to get the window title of external application
  3. How to check the window state of an external application
  4. How to get the title of the Active Window
  5. How to get Caption and Thread ID of Window under cursor
  6. How to terminate an application
  7. How to bring an external window to top using its caption
  8. How to Hide/Show the Title bar at Run-Time
  9. How to find and terminate running applications
  10. How to close the child windows in an external application.

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.