PDA

Click to See Complete Forum and Search --> : close it!, or something like it.


bob323
Aug 31st, 2000, 06:23 PM
Hi all,
I'm trying to create a program similar to close it!, whenever a popup window opens it compare the text and address with a list of text, if any of the text is the same in both lists then it closes the window.
I've gotten together most of the stuff but I can't figure out how to get ahold of the text of the popup, or the text of the address.
Anyone know how to get access to these?

Aug 31st, 2000, 07:10 PM
Use FindWindow. The following example will close Calculator as soon as it opens. Just change the name to whatever App you want to close.

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Long) As Long
Const WM_CLOSE = &H10
Const WM_CHAR = &H102
Const WM_KEYDOWN = &H100

Private Sub Timer1_Timer()
Dim PHWND As Long
PHWND = FindWindow(vbNullString, "Calculator")
If PHWND <> 0 Then
SendMessage PHWND, WM_CLOSE, 0, 0
DestroyWindow PHWND
End If
End Sub

Aug 31st, 2000, 07:10 PM
If you know the caption, than use this:

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10

Private Sub Timer1_Timer()
Dim winHwnd As Long
Dim RetVal As Long
winHwnd = FindWindow(vbNullString, "Caption")
If winHwnd <> 0 Then
RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
Else
Exit Sub
End If
End Sub