Show modeless form from a DLL

Discussion in 'AutoCAD' started by Tom Roberts, Jan 31, 2005.

  1. Tom Roberts

    Tom Roberts Guest

    I have started to move an application I have written in VBA over to VB with
    the intention of compiling it as a DLL.
    One of the first things I have noticed is that if I call a modeless form
    from the DLL it is a system wide form and appears in the task bar.

    Is it possible to call a modeless form from a DLL and have it behave like a
    modeless VBA UserForm.

    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia
     
    Tom Roberts, Jan 31, 2005
    #1
  2. Tom Roberts

    TomD Guest

    I have no clue how relevant this would be to your problem, but I was
    thinking about a case where I'd want to have a seperate file included in a
    VB routine and couldn't figure out how I would access when needed. (Sorry,
    I can't remember exactly what I was thinking about.)

    I was thinking that I could put in a RES file and copy it out to a temp
    folder when I needed. If there isn't a better solution, maybe you could do
    that with a DVB containing your form, then when needed, copy it to the temp
    folder and load it into Acad.
     
    TomD, Jan 31, 2005
    #2
  3. Tom Roberts

    Tom Roberts Guest

    To follow up on my own post I found that using the SetParent API function
    solves my problem
    So the DLL class code that exposes a method to show the form looks like
    this:

    '--------------------------
    Option Explicit
    Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long,
    ByVal hWndNewParent As Long) As Long
    Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long

    Public Sub ShowAbout()
    frmAbout.Show vbModeless
    SetParent frmAbout.hwnd, GetAcadHwnd
    End Sub

    Private Function GetAcadHwnd() As Long
    GetAcadHwnd = GetParent(GetParent(Application.ActiveDocument.hwnd))
    End Function
    '--------------------------

    After referencing the compiled DLL file in a VBA macro and creating an
    instance of the object I can call the ShowAbout method and the form is shown
    as a modeless form floating in the main AutoCAD window.

    --
    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia
     
    Tom Roberts, Feb 1, 2005
    #3
  4. Tom Roberts

    TomD Guest

    Thank you very much for posting the solution.
     
    TomD, Feb 1, 2005
    #4
  5. Tom Roberts

    Piero Guest

    Hi Tom,

    is it possible to insert complex VB control like datagrid?.
    How we could exchange data between VB & VBA?.

    Thanks a lot
     
    Piero, Feb 4, 2005
    #5
  6. Tom Roberts

    Tom Roberts Guest

    If you start a new ActiveX DLL project in VB you can create an interface
    using any controls you have a license for.
    Compile the DLL and start a new VBA project in AutoCAD.
    You can now reference (Tools -> References menu) the DLL and utilise the
    interface you created in VB.

    --
    Regards
    Tom Roberts
    __________________________
    MechWest Design & Drafting
    Perth, Western Australia
     
    Tom Roberts, Feb 7, 2005
    #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.