参考下面的例子:<br>var<br>w1,w2,w3:integer;<br>implementation<br><br>{$R *.DFM}<br><br>function enumwinproc(handle:hwnd;param:longint):boolean;<br>stdcall;<br>var<br>sz:array[0..132] of char;<br>begin<br>result:=true;<br>if getwindowtext(handle,sz,sizeof(sz))<>0 then<br>begin<br> if strpas(sz)='appclose' then<br> begin<br> if w1=0 then w1:=handle else w2:=handle;<br> end;<br>end;<br>end;<br><br>procedure TForm1.FormCreate(Sender: TObject);<br>begin<br>//判断当前程序是否只有一个在运行<br>w1:=0;w3:=0;<br>enumwindows(@enumwinproc,0);<br>if (w1<>0) and (w2<>0) then<br> begin<br> w3:=1;//判断是否在FormDestroy出现警告框的标记,等于1则不出现<br> sendmessage(w2,wM_close,0,0);<br> end;<br>end;<br>procedure TForm1.FormDestroy(Sender: TObject);<br>begin<br> if w3<>1 then<br> begin<br> application.messagebox('关闭','警告',48);<br> end; <br>end;<br><br>end.<br>