21 | 08 | 2017

Move Window 2 Front

When working from VB 6.0 you may the desire to command other applications. For that its usefull that when you are running a command to that application that it will be activated so it's clear what the code has done. For example when you are programming AutoCAD it could be helpfull if a user gives in coordinates to insert a block or draw a line. For that you will need to have the AutoCAD screen active. The code below show how you can activate AutoCAD and set it first on screen so users input.

Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Sub GetCoordinates()
'Code Source VisibleVisual.com
Dim Acad As AcadApplication
Dim ThisDrawing As AcadDocument
Dim pnt As Variant
Dim prompt1 As String
On Error Resume Next
'First check if AutoCAD is open!
Set Acad = GetObject(, "AutoCAD.Application")
If Err Then
MsgBox "Autocad Application is not open"
Exit Sub
  'If not open try to open AutoCAD
  Set Acad = CreateObject("AutoCAD.Application")
  'AutoCAD is not available
  If Err Then
  MsgBox "Cannot start AutoCAD!", vbExclamation, "Error starting AutoCAD"
  End If
End If
Acad.Visible = True
Set ThisDrawing = Acad.ActiveDocument
SetForegroundWindow Acad.hwnd
'Now that the AutoCAD window is open ask users input
prompt1 = vbCrLf & "Enter block insert point: "
ThisDrawing.ActiveSpace = acModelSpace
pnt = ThisDrawing.Utility.GetPoint(, prompt1)
MsgBox "You Have Selected: X=" & pnt(0) & " Y=" & pnt(1) & " Z=" & pnt(2)
End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles