toggle between Autocad and VB

Discussion in 'AutoCAD' started by alkimium, Oct 13, 2004.

  1. alkimium

    alkimium Guest

    Hello..

    I'm developing an vb6 application that works into autocad, using AutoCAD library. I've a problem, when i ask the user for prompting a point for example, or any or the utility object and set the focus to autocad, then, when the user has pick a point, autocad is not able to set focus to my vb apllication. Does anyone knows how to solve this.

    The code i use to set autocad focus is:
    Dim oAcadApp As AcadApplication
    ..
    ..
    ...
    AppActivate "autocad", 3
    ..
    Pto0 = oAcadApp.ActiveDocument.Utility.GetPoint(, "Pick up point")
    ..

    Thanks
     
    alkimium, Oct 13, 2004
    #1
  2. alkimium

    Mikko Guest

    AppActivate AcadApp.Caption
    .....
    cenPnt = acadUtil.GetPoint(, "BlaBlaBla")
    ....
    AppActivate("Your_VB_Application_Name")
     
    Mikko, Oct 13, 2004
    #2
  3. alkimium

    Herceg Guest

    hello!

    Did you solve the problem with mikko's suggestion? I ask it, because I have the same problem, and appactivate doesn't work for me. Here is my code:

    Modul name: Modul1
    Form name: Form1
    Button name: Commandbutton 1
    App start with Main

    Module code:
    Public ACADApp As AcadApplication

    Sub Main()
    Set ACADApp = GetObject(, "AutoCAD.Application.16")
    Form1.Show
    End Sub

    Sub proba()
    Unload Form1
    AppActivate ACADApp.Name
    pont = ACADApp.ActiveDocument.Utility.GetPoint(, "Enter a point in the alignment profile: ")
    'You can use the next line to chek, that acad gives back the focus, if you don't need user input
    ' ACADApp.ActiveDocument.SendCommand ("_line 0,0 1,1 " & Chr(27))
    Form1.Show
    AppActivate App.Title
    End Sub

    Form code:

    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

    Const HWND_BOTTOM = 1
    Const HWND_NOTOPMOST = -2
    Const HWND_TOP = 0
    Const HWND_TOPMOST = -1

    Const SWP_NOREDRAW = &H8
    Const SWP_NOSIZE = &H1
    Const SWP_NOZORDER = &H4
    Const SWP_SHOWWINDOW = &H40
    Const SWP_NOMOVE = &H2

    'The form will be the topmost window
    Public Sub Form_Load()
    Dim Success%
    Success% = SetWindowPos(Form1.hwnd, HWND_TOPMOST, 0, 0, 300, 50, SWP_NOSIZE Or SWP_NOMOVE)
    End Sub

    Private Sub Command1_Click()
    Module1.proba
    End Sub

    If you execute the code, you shold see that the form's title bar will be highlited thre times, but the focus remain on acad. This happens with any other acad command wich uses user input from the screen.
    It works with the line command.

    Please check this, and if you have different experience notice me.

    Thank you and good luck.
     
    Herceg, Oct 14, 2004
    #3
  4. alkimium

    alkimium Guest

    Thanks to Miko, but the problem was not solved. The focus stays at AutoCAD, all i get is teh same as you, the flashing of my application at the bottom windows bar.

    Thank you
     
    alkimium, Oct 14, 2004
    #4
  5. alkimium

    GTASteve Guest

    Do you have Windows PowerToys installed? (e.g. Tweak U.I.)

    If so, check if you have:
    General > Focus > [x] Prevent applications from stealing focus (checked)

    If so, adjust accordingly for your needs.
    (i'm guessing this is the issue, since you mentioned that the app is "flashing" in the taskbar)
     
    GTASteve, Oct 14, 2004
    #5
  6. alkimium

    alkimium Guest

    Thanks...

    Thats not the problem, i don't have Windows Power Toys installed. It must be another problem. I've tried it in diferent machines with different configurations but always the problem is the same.
     
    alkimium, Oct 14, 2004
    #6
  7. alkimium

    Herceg Guest

    I found some topic about acfocusctrl control, which may solves the problem in VBA, but I couldn't use it in VB.
    See this for more information:

    modal dialog in VB? (4 replies)
    Posted by: LIston, Kathleen
    Date: Feb/01/02 - 02:38 (GMT-12:00)
     
    Herceg, Oct 15, 2004
    #7
  8. alkimium

    alkimium Guest

    Nothing. It dosen't work.

    Thanks.
     
    alkimium, Oct 18, 2004
    #8
  9. alkimium

    hwalker Guest

    Check out the LinkMode and DoEvents Topics in the vb6 Help
     
    hwalker, Oct 18, 2004
    #9
  10. alkimium

    Herceg Guest

    I figured out I had the problem because of the SetWindowPos function. Without that the dialog disappears every time you select point, then it appears again. Below the code which works for me:

    Modul name: Modul1
    Form name: Form1
    Button name: Commandbutton 1
    App start with Main

    Module code:
    Public ACADApp As AcadApplication

    Sub Main()
    Set ACADApp = GetObject(, "AutoCAD.Application.16")
    'If the program starts from outside of acad
    AppActivate ACADapp.Name
    AppActivate App. title
    Form1.Show vbModal
    End Sub

    Sub proba()
    Appactivate ACADApp.Name
    pont = ACADApp.ActiveDocument.Utility.GetPoint(, "Enter a point in the alignment profile: ")
    AppActivate App.Title
    End Sub

    Form code:

    Private Sub Command1_Click()
    Module1.proba
    End Sub

    This program getting points on buttonclick until you close the form.

    I hope this helps you.
     
    Herceg, Oct 19, 2004
    #10
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.