VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



WinKill

by Matthew Grove (2 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (16 Votes)

WinKill destroys a window if you know its title bar caption.

Assumes
' Create a form a text box called txtName and a command button called cmdKill
API Declarations
' Api constants for General DeclarationsConst WM_DESTROY = &H2
Const WM_CLOSE = &H10' Api Functions for general declarations
Private Declare Function FindWindowA Lib "user32" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Integer
Private Declare Function SendMessageA Lib "user32" (ByVal hWnd As Integer, ByVal wMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long

Rate WinKill

'*************************************************************************
'WinKill Form Code
'*************************************************************************
Private Function Kill(hWnd&) 
 Dim Res& ' Ask it politely to close
 Res = SendMessageA(hWnd, WM_CLOSE, 0, 0)
 ' Kill it (just in case)
 Res = SendMessageA(hWnd, WM_DESTROY, 0, 0)
End Function
Private Sub cmdKill_Click()
 Dim hWnd& ' Get the window handle
 hWnd = FindWindowA(vbNullString, txtName.Text) ' Call the kill function
 Kill (hWnd)
End Sub

Download this snippet    Add to My Saved Code

WinKill Comments

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

Post your comment

Subject:
Message:
0/1000 characters