VB and AutoCAD

Discussion in 'AutoCAD' started by Barbarossa, Jun 15, 2004.

  1. Barbarossa

    Barbarossa Guest

    Hey guys,
    Is there a way of seting a VB form to be child to AutoCAD window?
     
    Barbarossa, Jun 15, 2004
    #1
  2. Barbarossa

    Barbarossa Guest

    I' think I found one way of doing this. Calling my VB applications through
    VLAX or VBA environment. I believe there will be a better way of doing
    this....
     
    Barbarossa, Jun 15, 2004
    #2
  3. Barbarossa

    youngman Guest

    hi
    could you tell me what is VLAX .

    i often see it ,but know nothing about it
    thank you
     
    youngman, Jun 16, 2004
    #3
  4. Barbarossa

    Jürg Menzi Guest

    Hi youngman

    VLAX or VLR are extended AutoLISP functions in Visual LISP.

    Cheers
     
    Jürg Menzi, Jun 16, 2004
    #4
  5. Barbarossa

    wivory Guest

    Yes. Create a BAS module containing the following:

    Code:
    Option Explicit
    '
    Public Const GWL_HWNDPARENT = (-8)
    '
    Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal wNewLong As Long) As Long
    Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    Public Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal aint As Long) As Long
    Public Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
    '
    Public Function FindAcadWindow(sTitle As String) As Long
    
    Dim hWndTmp As Long
    Dim nRet As Integer
    Dim TitleTmp As String
    Dim hWndOver As Integer
    
    'First find all the open windows so we can
    'loop through them and find the right one.
    hWndTmp = FindWindow(0&, 0&)
    
    Do Until hWndTmp = 0
    TitleTmp = Space$(256)
    nRet = GetWindowText(hWndTmp, TitleTmp, Len(TitleTmp))
    
    If nRet Then
    'Let's prepare to compare
    TitleTmp = UCase$(VBA.Left$(TitleTmp, nRet))
    'Now we see if the window we chased down actually
    'has the caption we want.
    If InStr(TitleTmp, UCase(sTitle)) >= 1 Then
    FindAcadWindow = hWndTmp
    'Check to make sure it is not the AutoCAD Today OR AutoCAD Startup Window
    If InStr(1, TitleTmp, "TODAY") >= 1 Then
    FindAcadWindow = 0
    ElseIf InStr(1, TitleTmp, "STARTUP") >= 1 Then
    FindAcadWindow = 0
    ElseIf InStr(1, TitleTmp, "HELP") >= 1 Then
    FindAcadWindow = 0
    Else
    Exit Do
    End If
    End If 'If InStr(TitleTmp, UCase(sTitle)) >= 1 Then
    End If 'If nRet Then
    
    hWndTmp = GetWindow(hWndTmp, GW_HWNDNEXT)
    Loop
    
    
    End Function
    
    In your Form module do the following:

    Code:
    Option Explicit
    '
    Dim OriginalParenthWnd As Long
    Dim lHwnd As Long
    '
    Private Sub Form_Load()
    Dim sAcadCaption As String
    '
    sAcadCaption = "AutoCAD whatever"
    lHwnd = FindAcadWindow(sAcadCaption)
    OriginalParenthWnd = SetWindowLong(Me.hwnd, GWL_HWNDPARENT, lHwnd)
    End Sub
    '
    Private Sub Form_Unload(Cancel As Integer)
    Call SetWindowLong(Me.hwnd, GWL_HWNDPARENT, OriginalParenthWnd)
    End Sub
    
    (Hope I got everything.)

    Regards

    Wayne Ivory
    IT Analyst Programmer
    Wespine Industries Pty Ltd
     
    wivory, Jun 16, 2004
    #5
  6. Barbarossa

    Barbarossa Guest

    Thank you for your posted VB code. It did work on some condition but did not
    make my VB application truly "child". Here is why. When I minimize the
    AutoCAD my test VB application got "minimized" (visible=false) with AutoCAD.
    Which was good. Then I close the AutoCAD and my test VB application stayed
    running invisible. Regardless from which state AutoCAD was closed the result
    was same. I had to shut it down through the task manager. Well, I can
    workaround this problem by putting a timer on my VB application to check if
    AutoCAD is running and shut down it if needed. I will be thankful to know if
    there is another (better) way of accomplishing this same task.



    Thanks


     
    Barbarossa, Jun 17, 2004
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.