Tip: How to close another app

101 views
Skip to first unread message

Zoran

unread,
Mar 15, 2006, 10:59:24 AM3/15/06
to Fun Delphi Initiative
Most of you know how to do this already. I post this just for the less
experienced Delphians.

To close another application from Delphi program send to that
application's main window WM_CLOSE message (PostMessage API declared in
the Windows unit). You must pass the handle of the window to which you
want to post the message. This handle you can obtain by using the
FindWindow API (also declared in the Windows unit).

uses Windows, Messages;

procedure TForm1.Button1Click(Sender: TObject);
var
h: HWND;
begin
h := FindWindow(nil,
'Caption-of-the-main-form-of-app-you-want-to-close');
if h <> 0
then PostMessage(h, WM_CLOSE, 0, 0);
end;

D.Tkalcec

unread,
Mar 17, 2006, 8:21:00 AM3/17/06
to Fun Delphi Initiative
I will be organizing the Web pages a bit during the next week and
hopefuly to get some free time to do some coding to make our first
working web portal. Then, all the tips and tricks posted here will be
ported to the website.

Cheers,
Danijel Tkalcec

Reply all
Reply to author
Forward
0 new messages