Tools Links Login

WinKill

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

Original Author: Matthew Grove

Assumptions

' 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

Code

'*************************************************************************
'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

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 91 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Comments

No comments have been added for this post.

You must be logged in to make a comment.