Close another application

How can I close another application, how can I send Terminate message to any specified application ?

Motaz
LVL 7
MotazAsked:
Who is Participating?
 
DrDelphiConnect With a Mentor Commented:
Hi... I'm not looking for any more points (thank you by the way)... I just want to point out that what I suggested before is all you really need...behold:

var winHandle:integer;
begin
    WinHandle:=FindWindow('OpusApp',nil);
{OpusApp is the ClassName of  a Word window}
    if WinHandle<>0 then
    begin
      sendmessage(WinHandle,Wm_Close,0,0);
    end
    else
      Showmessage('Error');
end;




0
 
DrDelphiCommented:
Here we shut down Eudora ( as an example) without any prior knowledge of either the windowClass or the windowText:


var winHandle:integer;
    loopint:integer;
begin
  Listbox1.Items.clear;
  EnumWindows(@EnumWindowsCallBack, 0);
  For loopint:=0 to listbox1.Items.count-1 do
  begin
    if Pos('Eudora', Listbox1.Items.Strings[loopint])>0 then
    begin
      WinHandle:=FindWindow(nil,Pchar(ListBox1.Items.Strings[loopint]));
      if WinHandle<>0 then
          sendmessage(WinHandle,Wm_Close,0,0)
      else
         Showmessage('Error');
    end;
   end;
end;
0
 
DrDelphiCommented:
Here we shut down Eudora ( as an example) without any prior knowledge of either the windowClass or the windowText:


var winHandle:integer;
    loopint:integer;
begin
  Listbox1.Items.clear;
  EnumWindows(@EnumWindowsCallBack, 0);
  For loopint:=0 to listbox1.Items.count-1 do
  begin
    if Pos('Eudora', Listbox1.Items.Strings[loopint])>0 then
    begin
      WinHandle:=FindWindow(nil,Pchar(ListBox1.Items.Strings[loopint]));
      if WinHandle<>0 then
          sendmessage(WinHandle,Wm_Close,0,0)
      else
         Showmessage('Error');
    end;
   end;
end;
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
DrDelphiCommented:
Sorry.. I seem to have stuttered a little there... <g>

0
 
rwilson032697Commented:
Listening
0
 
MotazAuthor Commented:
Why not to look for more points?

Your answer helps me alot.

Motaz
www.geocities.com/motaz1
0
All Courses

From novice to tech pro — start learning today.