a: winexec('b.exe',sw_shownormal); b:use shellapi; var h:THandle; begin h:=findwindow(nil,'a的标题'); //注意修改为自己的窗口标题 if h <> 0 then sendmessage(h,WM_CLOSE,0,0); end;
TO nhdj(柳柳荷叶清清水) 你的方法一定程度是可以的 但是特殊情况你的代码应付不了了例如winamp在播放歌曲的时候 他的标题是在变化的真的方法是要用进程守侯的方法有兴趣的话 和我联系一下
那我就借两位老兄的经验,小结一下: a中调用B的单元引用:shellapi 然后用shellexecute(form1.handle,'open',pchar('b.exe'),'-s','',sw_shownormal;var th:HWND; begin th:=findwindow(nil,'a的标题'); if th<>0 then begin sendmessage(th,wm_close,0,0); end;
关闭听楼下
winexec('b.exe',sw_shownormal);
b:use shellapi;
var
h:THandle;
begin
h:=findwindow(nil,'a的标题'); //注意修改为自己的窗口标题
if h <> 0 then
sendmessage(h,WM_CLOSE,0,0);
end;
你的方法一定程度是可以的
但是特殊情况你的代码应付不了了例如winamp在播放歌曲的时候 他的标题是在变化的真的方法是要用进程守侯的方法有兴趣的话 和我联系一下
a中调用B的单元引用:shellapi
然后用shellexecute(form1.handle,'open',pchar('b.exe'),'-s','',sw_shownormal;var
th:HWND;
begin
th:=findwindow(nil,'a的标题');
if th<>0 then
begin
sendmessage(th,wm_close,0,0);
end;