Solved

Close another program from a Delphi program

Posted on 2001-06-13
5
265 Views
Last Modified: 2010-04-06
My problem is the following:

On a Windows NT server I have a program scheduled to run once a day. This program always ends with a message box, saying that the operations was successful or not. I must click OK to close this message box.
So, when I don't look at my server for ten days, there are ten message boxes on the screen. The Windows NT task manager also shows ten programs open.

I now think of a solution with a Delphi program that closes this particular program on the server. I can schedule it i.e. one hour after the scheduling time of the other program. The only thing I like to know is: can I close another program from within my Delphi program?

Thanks,
JDN
0
Comment
Question by:JDN
5 Comments
 
LVL 8

Accepted Solution

by:
Cesario earned 50 total points
Comment Utility
Hi JDN,

yes you can do it ;-)

You can send the application a WM_QUIT message:

PostMessage(FindWindow(Nil, 'window caption'), WM_QUIT, 0, 0);

Where "window caption" is the caption of the window that you
are sending the message to.

Best Regards

Cesario
0
 
LVL 4

Expert Comment

by:Colin_Dawson
Comment Utility
How about something like this....

Procedure CloseProg;
Var
  MyHandle : THandle;
Begin
  MyHandle := FindWindow( null, 'Messagebox Title' );
  If MyHandle <> null Then
  Begin
    PostMessage( MyHandle, WM_Close, 0, 0 );
  End;
End;

I have no idea if this code will work, but it might be worth a try :-)
0
 
LVL 20

Expert Comment

by:Madshi
Comment Utility
Please use WM_CLOSE. WM_QUIT is not documented to work when being sent to a window, instead it should be sent to a *thread*, and WM_CLOSE is cleaner anyway...

Regards, Madshi.
0
 
LVL 4

Expert Comment

by:Colin_Dawson
Comment Utility
aaarrrggghhh you beat me by 4 minutes.  :-)
0
 
LVL 1

Author Comment

by:JDN
Comment Utility
Thank you all for your help.
And sorry Colin, only one can be the winner...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now