将cad嵌入到vb中

Option Explicit 
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 
Private Sub Form_Load()
    
    On Error GoTo ErrTrap
    Dim acadApp As Object
    Set acadApp = CreateObject("AutoCAD.Application")
    acadApp.Visible = True
    lHwnd = GetParent(GetParent(acadApp.Activedocument.hwnd))
    If lHwnd = 0 Then Exit Sub
    SetParent lHwnd, Form1.hwnd
    Exit Sub
    
ErrTrap:
    On Error GoTo 0
End Sub 
Private Sub Form_Unload(Cancel As Integer)
    If lHwnd = 0 Then Exit Sub
    SetParent lHwnd, 0
End Sub
posted @ 2011-04-17 16:50  pensir  阅读(1069)  评论(0编辑  收藏  举报