Link to home
Start Free TrialLog in
Avatar of kaloyan
kaloyan

asked on

How to close applications?

How to close running application with my programm?
I am using Delphi 3.
Avatar of kretzschmar
kretzschmar
Flag of Germany image

hi kaloyan,

if you know the WindowTitle of the App you want to close, you can do it with this code

procedure TForm1.Button1Click(Sender: TObject);
var
  TheHandle : THandle;
begin
  TheHandle := Findwindow(NIL, 'Microsoft Excel'); {Excel, no open documents}
  If TheHandle > 0 then SendMessage(TheHandle,WM_CLOSE,0,0);
end;

meikl
Avatar of Madshi
Madshi

If you want the program to ask the user whether the modified file shall be saved, use meikl's solution, otherwise send a WM_QUIT instead of a WM_CLOSE.

Regards, Madshi.
ASKER CERTIFIED SOLUTION
Avatar of zwarte
zwarte
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial