CodeItBetter Programming Another VB Programming Blog

Check & Terminate Process using Window Title

Posted on July 11, 2011
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
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.