在vb.net的Form中内嵌AutoCAD
yuzzw 2006-07-27 11:39:59 在vb.net的Form中内嵌AutoCAD,代码如下:
Public Class Form1
Inherits System.Windows.Forms.Form
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private lHwnd As Long
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent() 调用之后添加任何初始化
initCAD()
End Sub
'窗体重写 dispose 以清理组件列表。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗体设计器所必需的
Private components As System.ComponentModel.IContainer
'注意: 以下过程是 Windows 窗体设计器所必需的
'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
components = New System.ComponentModel.Container
Me.Text = "Form1"
End Sub
#End Region
Private Sub initCAD()
On Error GoTo ErrTrap
Dim acadApp As Object
acadApp = CreateObject("AutoCAD.Application")
acadApp.Visible = True
lHwnd = GetParent(GetParent(acadApp.Activedocument.hwnd))
If lHwnd = 0 Then Exit Sub
SetParent(lHwnd, Me.Handle.ToInt32())
Exit Sub
ErrTrap:
On Error GoTo 0
End Sub
End Class
运行现象是分别打开两个窗口,而不是内嵌,请问why?