VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Update Close Window (partial title)

by Che (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (7 Votes)

This will get the hWnd of freaky programs that change class names every time you start it, and then close it. The only thing you need to know is part of the Titlename (Netsc, instead of "Web Page Title" - Netscape). This WILL close Microsoft Internet Explorer (old version wouldn't) now =Þ. Also, I made it so that you don't have to have a form named "Form1" (by using EnumWindows)

API Declarations
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As Long) As Long
Declare Function getwindow Lib "user32" Alias "GetWindow" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function EnumWindows& Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long)
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 Const WM_CLOSE = &H10
Public AppTitle As String
Public ApphWnd As Long

Rate Update Close Window (partial title)

Function GetCaption(WindowhWnd)
  hwndlength% = GetWindowTextLength(WindowhWnd)
  hWndTitle$ = String$(hwndlength%, 0)
  a% = GetWindowText(WindowhWnd, hWndTitle$, (hwndlength% + 1))
  GetCaption = hWndTitle$
End Function
Function CheckAllWindows(ByVal hwnd As Long, lParam As Long) As Boolean
  Dim a
  a = LCase(GetCaption(hwnd))
  If InStr(1, a, LCase(AppTitle)) <> 0 Then
    ApphWnd = hwnd
    CheckAllWindows = False
  Else
    CheckAllWindows = True
  End If
End Function
Sub KillWin(Title As String)
  Dim a
  AppTitle = Title
  EnumWindows AddressOf CheckAllWindows, 0&
  If ApphWnd = 0 Then Exit Sub
  a = PostMessage(ApphWnd, WM_CLOSE, 0&, 0&)
End Sub
'-----Use KillWin to close the window. KillWin "Title"

Download this snippet    Add to My Saved Code

Update Close Window (partial title) Comments

No comments have been posted about Update Close Window (partial title). Why not be the first to post a comment about Update Close Window (partial title).

Post your comment

Subject:
Message:
0/1000 characters