?
Solved

Simple Visual Basic Program

Posted on 2003-03-03
5
Medium Priority
?
134 Views
Last Modified: 2013-11-25
how would i go about building a program that would detect a new window, delay about 5 seconds, then close it.

I would like for this program to exist in the background and be able to run for an extended amount of time.

Thanks,
Adam Miller
0
Comment
Question by:dullertap
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 300 total points
ID: 8061060
Is it a specific window you are trying to close? If you know the windows caption it can be done using the FindWindow API:

' add a timer and set the interval to 1000
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 Sub Sleep Lib "kernel32" (ByVal milliseconds As Long)
Private Const WM_CLOSE = &H10

Private Sub Timer1_Timer()
' where "Untitled - Notepad" is the window caption
CloseProgram ("Untitled - Notepad")
End Sub

Private Sub CloseProgram(ByVal Caption As String)
Dim Handle
Handle = FindWindow(vbNullString, Caption)
If Handle = 0 Then Exit Sub
' wait 5 secs
Sleep 5000
SendMessage Handle, WM_CLOSE, 0&, 0&
End Sub
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 8065855
Why are you trying to write this?

mlmcc
0
 

Expert Comment

by:CleanupPing
ID: 8940391
dullertap:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9024078
Moderator, my recommended disposition is:

    Accept vinnyd79's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question