Share
 
 

About Controlling the Application Window (ActiveX)

The ability to control the Application window allows developers the flexibility to create effective and intelligent applications.

There will be times when it is appropriate for your application to minimize the AutoCAD window, perhaps while your code is performing work in another application such as Excel. Additionally, you will often want to verify the state of the AutoCAD window before performing such tasks as prompting for input from the user.

Using methods and properties found on the Application object, you can change the position, size, and visibility of the Application window. You can also use the WindowState property to minimize, maximize, and check the current state of the Application window.

Position and size the Application window

This example uses the WindowTop, WindowLeft, Width, and Height properties to position the AutoCAD Application window in the upper-left corner of the screen and size it to 400 pixels wide by 400 pixels high.

AutoLISP
(vl-load-com)
(defun c:Ch3_PositionApplicationWindow ()
    (setq acadObj (vlax-get-acad-object))
    (vla-put-WindowTop acadObj 0)
    (vla-put-WindowLeft acadObj 0)
    (vla-put-width acadObj 400)
    (vla-put-height acadObj 400)
)
VBA (AutoCAD Only)
Sub Ch3_PositionApplicationWindow()
  ThisDrawing.Application.WindowTop = 0
  ThisDrawing.Application.WindowLeft = 0
  ThisDrawing.Application.width = 400
  ThisDrawing.Application.height = 400
End Sub

Maximize the Application window

AutoLISP
(vl-load-com)
(defun c:Ch3_MaximizeApplicationWindow ()
    (setq acadObj (vlax-get-acad-object))
    (vla-put-WindowState acadObj acMax)
)
VBA (AutoCAD Only)
Sub Ch3_MaximizeApplicationWindow()
  ThisDrawing.Application.WindowState = acMax
End Sub

Minimize the Application window

AutoLISP
(vl-load-com)
(defun c:Ch3_MinimizeApplicationWindow ()
    (setq acadObj (vlax-get-acad-object))
    (vla-put-WindowState acadObj acMin)
)
VBA (AutoCAD Only)
Sub Ch3_MinimizeApplicationWindow()
  ThisDrawing.Application.WindowState = acMin
End Sub

Find the current state of the Application window

This example queries the state of the Application window and displays the state in a message box to the user.

AutoLISP
(vl-load-com)
(defun c:Ch3_CurrentWindowState()
    (setq acadObj (vlax-get-acad-object)
          CurrWindowState (vla-get-WindowState acadObj)
          msg "")

    (cond
      ((= CurrWindowState 1)(setq msg "normal"))
      ((= CurrWindowState 2)(setq msg "minimized"))
      ((= CurrWindowState 3)(setq msg "maximized"))
    )

    (alert (strcat "The application window is " msg))
)
VBA (AutoCAD Only)
Sub Ch3_CurrentWindowState()
  Dim CurrWindowState As Integer
  Dim msg As String
  CurrWindowState = ThisDrawing.Application.WindowState
  msg = Choose(CurrWindowState, "normal", "minimized", "maximized") 
  MsgBox "The application window is " + msg
End Sub

Make the Application window invisible

The following code uses the Visible property to make the AutoCAD application invisible to the end user.

AutoLISP
(defun c:Ch3_HideWindowState ()
    (setq acadObj (vlax-get-acad-object))
    (vla-put-Visible acadObj :vlax-false)
)
VBA (AutoCAD Only)
Sub Ch3_HideWindowState()
  ThisDrawing.Application.Visible = False
End Sub

Was this information helpful?