请问我使用下面的怎么不可以把autocad的窗口放到delphi的一个form里面?错在哪里啊?
procedure TForm1.Button1Click(Sender: TObject);
var
 AcadApp : OleVariant;
 phwnd:hwnd;
 chwnd:hwnd;
begin
    AcadApp := CreateOleObject('AutoCad.Application');
    AcadApp.visible := true;            //这里是对的
    phwnd:=GetParent(GetParent(acadApp.Activedocument.hwnd));
    chwnd:=form1.Handle ;
    if phwnd = null then
     exit
    else
      setparent(phwnd,chwnd);
end;

解决方案 »

  1.   

    在vb里面可以使用这个
    Private Type RECT
        Left As Long
        Top As Long
        Right As Long
        Bottom As Long
    End TypePrivate acadApp As Object 
    Private lHwnd As Long '保存ACAD应用程序的窗口句柄
    Private lState As Long '保存ACAD的初始窗口状态
    Private r As RECT '保存ACAD的初始窗口位置Private Sub Form_Load()
        
        On Error GoTo ErrTrap
        Set acadApp = GetObject(, "AutoCAD.Application")
        acadApp.Visible = True
        lHwnd = GetParent(GetParent(acadApp.Activedocument.hwnd))
        If lHwnd = 0 Then Exit Sub
        lState = acadApp.WindowState
        acadApp.WindowState = 1 '设置ACAD的窗口状态为默认,用于保存窗口位置。
        GetWindowRect lHwnd, r
        SetParent lHwnd, Form1.hwnd
        Form1.ScaleMode = vbPixels '将VB窗体默认的缇单位改为以像素为单位。
        SetWindowPos lHwnd, 0, Form1.ScaleLeft, Form1.ScaleTop, Form1.ScaleWidth, Form1.ScaleHeight, 0
        Exit Sub
        
    ErrTrap:
        On Error GoTo 0
    End SubPrivate Sub Form_Resize()
        SetWindowPos lHwnd, 0, Form1.ScaleLeft, Form1.ScaleTop, Form1.ScaleWidth, Form1.ScaleHeight, 0
    End SubPrivate Sub Form_Unload(Cancel As Integer)
        If lHwnd = 0 Then Exit Sub
        SetParent lHwnd, 0
        SetWindowPos lHwnd, 0, r.Left, r.Top, r.Right - r.Left, r.Bottom - r.Top, 0
        acadApp.WindowState = lState
        Set acadApp = Nothing
    End Sub
    上面的还支持VB的窗体缩放时ACAD的窗口自动跟随缩放。
      

  2.   

    AcadApp.Parent:=form1
    这句不行吧
      

  3.   

    phwnd:=GetParent(GetParent(acadApp.Activedocument.hwnd));
        chwnd:=form1.Handle ;
        if phwnd = null then
         exit
        else
          setparent(phwnd,chwnd);
      

  4.   

    phwnd:=GetParent(acadApp.Activedocument.hwnd);
        chwnd:=form1.Handle ;
        if phwnd = null then
         exit
        else
          setparent(phwnd,chwnd);