procedure TForm1.Button1Click(Sender: TObject);
var
obj_Acad :OleVariant;
Title:string;
ACAD_HWND:Hwnd;
begin
try
obj_Acad:=GetActiveOleObject('AutoCAD.Application.14'); //找已打开的AutoCAD
except
obj_Acad:=CreateOleObject('AutoCAD.Application.14'); //如还没打开则打开AutoCAD
end;
obj_Acad.Visible:=True; //如果是用obj_Acad:=CreateOleObject('AutoCAD.Application.14');
//则这句不能省
//把AutoCAD设为最前窗口。
Title:=obj_Acad.Caption;
acad_Hwnd:=Findwindow(nil,Pchar(Title));
ShowWindow(ACAD_HWND, SW_RESTORE);
SetForegroundWindow(ACAD_HWND);
//设置AutoCAD的窗口状态
obj_Acad.WindowState:= //试一试0,1,2...因为如下的常量在Delphi中没定义
{ WindowState acWindowState enum; read-write
acMin: The window is minimized.
acMax: The window is maximized.
acNorm: The window is normal. (Neither minimized nor maximized.)
}
obj_Acad.Quit; //这个退出AutoCAD
end;