?
Solved

Close another program from a Delphi program

Posted on 2001-06-13
5
Medium Priority
?
272 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
[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 8

Accepted Solution

by:
Cesario earned 200 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

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