也可用Post WM_QUIT消息。
如下:procedure TForm1.Button1Click(Sender: TObject);
var
h : hwnd ;
begin
h := Findwindow(nil,'程序主窗口名') ;
if h <> 0 then
Postmessage(h,WM_QUIT,0,0);end;
如下:procedure TForm1.Button1Click(Sender: TObject);
var
h : hwnd ;
begin
h := Findwindow(nil,'程序主窗口名') ;
if h <> 0 then
Postmessage(h,WM_QUIT,0,0);end;
可得给分呀
sendmessage(handle,Wm_close,0,0)
代码如下:
假设要终止的程序的文件名为:project2.exe,那么例程如下:
uses tlhelp32;
var
lppe:tprocessentry32;
sshandle:thandle;
hh:hwnd;
found:boolean;
begin
sshandle:=createtoolhelp32snapshot(TH32CS_SNAPALL,0);
found:=process32first(sshandle,lppe);
while found do
begin
//进行你的处理其中lppe.szExefile就是程序名。
if uppercase(extractfilename(lppe.szExeFile))='PROJECT2.EXE' then
begin
hh:=OpenProcess(PROCESS_ALL_ACCESS,true,lppe.th32ProcessID);
TerminateProcess(hh,0);
end;
found:=process32next(sshandle,lppe);
end;
end;