下面语句在cls中运行,名为AcadApi
Dim AcadApp As AutoCAD.AcadApplication
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 Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type Private lHwnd As Long '保存ACAD应用程序的窗口句柄
Private lState As Long '保存ACAD的初始窗口状态
Private r As RECT '保存ACAD的初始窗口位置
Function AcadApi()
On Error Resume Next
Set AcadApp = GetObject(, "AutoCAD.Application.16")
If Err Then
Err.Clear
Set AcadApp = CreateObject("AutoCAD.Application.16")
End If
AcadApp.Visible = True
Dim objEntity As Object
Dim DwgName As String
DwgName = App.Path & "\HG20592Modle\HG20593Modle.dwg"
Set objEntity = AcadApp.Documents '.Open(DwgName)
''
On Error Resume Next ' trap any load errors
'ThisDrawing.Linetypes.Load linetypeName, "acad.lin" lHwnd = GetParent(GetParent(AcadApp.ActiveDocument.hwnd))
If lHwnd = 0 Then Exit Function
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
SetWindowPos lHwnd, 0, Form1.ScaleLeft, Form1.ScaleTop, Form1.ScaleWidth * 2.7, Form1.ScaleHeight * 2.8, 0
Exit Function
ErrTrap:
On Error GoTo 0
End Function在Form1中
全局变量
Dim CadApp As New AcadApi
Private Sub Form_Load()
CadApp.AcadApi
End Sub
在Form1运行正常。
语句各位大侠:
在Sstab的n选项卡中装载Cad?
如何将上面程序的Form1改为能在SsTab的n选项卡中装载。
谢谢。
Dim AcadApp As AutoCAD.AcadApplication
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 Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type Private lHwnd As Long '保存ACAD应用程序的窗口句柄
Private lState As Long '保存ACAD的初始窗口状态
Private r As RECT '保存ACAD的初始窗口位置
Function AcadApi()
On Error Resume Next
Set AcadApp = GetObject(, "AutoCAD.Application.16")
If Err Then
Err.Clear
Set AcadApp = CreateObject("AutoCAD.Application.16")
End If
AcadApp.Visible = True
Dim objEntity As Object
Dim DwgName As String
DwgName = App.Path & "\HG20592Modle\HG20593Modle.dwg"
Set objEntity = AcadApp.Documents '.Open(DwgName)
''
On Error Resume Next ' trap any load errors
'ThisDrawing.Linetypes.Load linetypeName, "acad.lin" lHwnd = GetParent(GetParent(AcadApp.ActiveDocument.hwnd))
If lHwnd = 0 Then Exit Function
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
SetWindowPos lHwnd, 0, Form1.ScaleLeft, Form1.ScaleTop, Form1.ScaleWidth * 2.7, Form1.ScaleHeight * 2.8, 0
Exit Function
ErrTrap:
On Error GoTo 0
End Function在Form1中
全局变量
Dim CadApp As New AcadApi
Private Sub Form_Load()
CadApp.AcadApi
End Sub
在Form1运行正常。
语句各位大侠:
在Sstab的n选项卡中装载Cad?
如何将上面程序的Form1改为能在SsTab的n选项卡中装载。
谢谢。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货