我的做法是 打开一个DLL 就往一个全局的容器里面增加一笔这个DLL的信息 关闭的时候 在这个容器里面循环 关闭每一个DLL 再关闭主程序 // 退出所有正在运行的作业function TfrmMain.DoCloseChild: Boolean; var i: integer; mHandle: HWND; begin Result := True; for i := FDlls.Count - 1 downto 1 do begin mHandle := TForm(TDLLItem(FDlls.Items[i]).Form).Handle; if not (SendMessage(mHandle, WM_CLOSE, 0, 0) = 0) then begin Result := False; Break; end; end; end;
var
i: integer;
mHandle: HWND;
begin
Result := True;
for i := FDlls.Count - 1 downto 1 do
begin
mHandle := TForm(TDLLItem(FDlls.Items[i]).Form).Handle;
if not (SendMessage(mHandle, WM_CLOSE, 0, 0) = 0) then
begin
Result := False;
Break;
end;
end;
end;