在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?
...全文
132 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
yuzzw 2006-09-06
  • 打赏
  • 举报
回复
经查是由于.net不支持像vb form里可以内嵌ole容器。
yuzzw 2006-08-03
  • 打赏
  • 举报
回复
是否SetParent(lHwnd, Me.Handle.ToInt32())这方法使用不当,还是另有其法?

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧