Solved

Close another program from a Delphi program

Posted on 2001-06-13
5
267 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
ID: 6186221
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
ID: 6186250
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
ID: 6186814
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
ID: 6187810
aaarrrggghhh you beat me by 4 minutes.  :-)
0
 
LVL 1

Author Comment

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

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi selector screen 2 79
When i run adoquery my application freezes 26 166
PHP preg_replace code convert to Delphi 14 56
Firemonkey allowing RTL on android 6 32
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

778 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