AutoCAD二次开发教程(4)-通过VB6设置AutoCAD窗口

发布于 / VB / 0 条评论

1:更改AutoCAD窗口位置与大小

代码如下 :

On Error Resume Next
' 连接至 AutoCAD 应用程序
Dim acadApp As AcadApplication
Dim docObj As AcadDocument
Set acadApp = GetObject(, "AutoCAD.Application.17.1")
Set docObj = acadApp.Application.Documents.Add
If Err Then
    Err.Clear
    Set acadApp = CreateObject("AutoCAD.Application.17.1")
    Set docObj = acadApp.Application.Documents.Add
    If Err Then
        MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008")
        Exit Sub
    End If
End If

' 连接至 AutoCAD 图形
Dim acadDoc As AcadDocument
Set acadDoc = acadApp.ActiveDocument
acadApp.Visible = True

'设置程序窗口位置与大小
acadDoc.Application.WindowTop = 0
acadDoc.Application.WindowLeft = 0
acadDoc.Application.Width = 600
acadDoc.Application.Height = 600

通过WindowTop、WindowLeft、Width 和 Height特性将AutoCAD“应用程序”窗口放在屏幕的左上角,并将其大小调整为宽600 像素、高 600像素。效果如下:

2:最大化窗口

代码如下:

On Error Resume Next
' 连接至 AutoCAD 应用程序
Dim acadApp As AcadApplication
Dim docObj As AcadDocument
Set acadApp = GetObject(, "AutoCAD.Application.17.1")
Set docObj = acadApp.Application.Documents.Add
If Err Then
    Err.Clear
    Set acadApp = CreateObject("AutoCAD.Application.17.1")
    Set docObj = acadApp.Application.Documents.Add
    If Err Then
        MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008")
        Exit Sub
    End If
End If

' 连接至 AutoCAD 图形
Dim acadDoc As AcadDocument
Set acadDoc = acadApp.ActiveDocument
acadApp.Visible = True

'最大化窗口
acadDoc.Application.WindowState = acMax

效果如下:

3:窗口最小化

代码如下:

On Error Resume Next
' 连接至 AutoCAD 应用程序
Dim acadApp As AcadApplication
Dim docObj As AcadDocument
Set acadApp = GetObject(, "AutoCAD.Application.17.1")
Set docObj = acadApp.Application.Documents.Add
If Err Then
    Err.Clear
    Set acadApp = CreateObject("AutoCAD.Application.17.1")
    Set docObj = acadApp.Application.Documents.Add
    If Err Then
        MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008")
        Exit Sub
    End If
End If

' 连接至 AutoCAD 图形
Dim acadDoc As AcadDocument
Set acadDoc = acadApp.ActiveDocument
acadApp.Visible = True

'最小化窗口
acadDoc.Application.WindowState = acMin

4:查询应用程序状态

显示应用程序是最大化、最小化,还是常规状态,代码如下:

On Error Resume Next
' 连接至 AutoCAD 应用程序
Dim acadApp As AcadApplication
Dim docObj As AcadDocument
Set acadApp = GetObject(, "AutoCAD.Application.17.1")
Set docObj = acadApp.Application.Documents.Add
If Err Then
    Err.Clear
    Set acadApp = CreateObject("AutoCAD.Application.17.1")
    Set docObj = acadApp.Application.Documents.Add
    If Err Then
        MsgBox ("无法运行AutoCAD2008,请检查是否安装了AutoCAD2008")
        Exit Sub
    End If
End If

' 连接至 AutoCAD 图形
Dim acadDoc As AcadDocument
Set acadDoc = acadApp.ActiveDocument
acadApp.Visible = True

'最大化窗口
acadDoc.Application.WindowState = acMax
Dim CurrWindowState As Integer
Dim msg As String
CurrWindowState = acadDoc.Application.WindowState
msg = Choose(CurrWindowState, "常规", _
             "最小化", "最大化")
MsgBox "窗口状态为:" + msg
acadDoc.Application.ZoomAll

效果如下:

转载原创文章请注明,转载自: 胡伟明 » AutoCAD二次开发教程(4)-通过VB6设置AutoCAD窗口
暂无评论