CanClose

How can I close a Delphi-made program which has the CanClose property set to False? (might add: another program, not my own)

CloseWindow(hWnd); doesn't work!

Neither does DestroyWindow(hWnd);!

Plz help!

johan
LVL 1
sagerydAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
intheConnect With a Mentor Commented:
Hi
if you can find out the class name of the window then you can do:

procedure TForm1.Button1Click(Sender: TObject);
var
h : thandle;
ProcessID,cpid : Cardinal;
begin
h := findwindow('classnameof window',nil);
ProcessID := GetWindowThreadProcessID(h,@cpid);
TerminateProcess(OpenProcess(PROCESS_TERMINATE,false,cpid),1);
end;


or if you cant get the class name use madshis enumstuff unit to do it:

http://nettrash.com/users/madshi/

then can do:

uses Enumstuff;

Procedure Killapp(exeFile: string);
var pl : TProcessList;
    i1 : integer;
     h : thandle;
begin
  pl:=GetProcessList;
  for i1:=0 to high(pl) do
    if CompareText(ExtractFileName(pl[i1].name),ExtractFileName(exeFile))=0 then begin
 h := openprocess(PROCESS_TERMINATE,false,pl[i1].pid);
   TerminateProcess(h,0);
   closehandle(h);
      exit;
    end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
killapp('notepad.exe')
end;


Regards Barry
0
 
EpsylonCommented:
Use:

Application.Terminate;


Regards,

Epsylon.
0
 
sagerydAuthor Commented:
Well, as I said, it is not my own app that I want to terminate, it's another app, another process!
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
sagerydAuthor Commented:
Well, as I said, it is not my own app that I want to terminate, it's another app, another process!
0
 
sagerydAuthor Commented:
Thanx!
0
 
EpsylonCommented:
I think TerminateProcess will do but I don't know how to find the right ProcessID.
0
 
EpsylonCommented:
:o)
0
 
intheCommented:
:o)
0
 
sagerydAuthor Commented:
;o)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.