common dialog control

Discussion in 'AutoCAD' started by elefebvre, Sep 23, 2004.

  1. elefebvre

    elefebvre Guest

    hi,

    i know that the commong dialog control from windows doesn't work in VBA. So I am looking for some kind of free-ware dialog control.

    Anybody has a lead?

    thanks in advance,

    Emmanuel

    PS: or maybe there are other solutions?
     
    elefebvre, Sep 23, 2004
    #1
  2. Hi,

    The Dialog box works perfectly well with VBA. The issues of not using it
    are associated with the fact that you are not entitled to distribute
    software using it.

    Do a web search. You will find dozens of options for freeware
    replacements - inclusive of source code in many cases.

    --

    Regards


    Laurie Comerford
    www.cadapps.com.au

    So I am looking for some kind of free-ware dialog control.
     
    Laurie Comerford, Sep 23, 2004
    #2
  3. elefebvre

    VBA Guest

    The CommonDialogBox works just fine in VBA. However, you do not have a
    license to use the ActiveX control. Not to worry, you can easily implement
    the control through Windows API code


    So I am looking for some kind of free-ware dialog control.
     
    VBA, Sep 23, 2004
    #3
  4. elefebvre

    bcoward Guest

    bcoward, Sep 23, 2004
    #4
  5. elefebvre

    elefebvre Guest

    how?
     
    elefebvre, Sep 23, 2004
    #5
  6. elefebvre

    elefebvre Guest

    i tried that. I think that only works for VB. I work in VBA.

    At the first declare function, it tells me:

    Compile error:
    "User-Defined Type not defined"

    what could the problem be?

    Emmanuel
     
    elefebvre, Sep 23, 2004
    #6
  7. elefebvre

    VBA Guest

    You are trying to use an object whose TypeLib you have not referenced.
     
    VBA, Sep 23, 2004
    #7
  8. elefebvre

    elefebvre Guest

    I tried to reference it but it tells me that I "can't add a reference to this file". Probably again because it is not licensed (I don't work with VB).

    any way around this?
     
    elefebvre, Sep 23, 2004
    #8
  9. You looking to grab a file or a folder?

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...
     
    Mike Tuersley, Sep 23, 2004
    #9
  10. Frank Oquendo, Sep 23, 2004
    #10
  11. James Belshan, Sep 23, 2004
    #11
  12. elefebvre

    elefebvre Guest

    hey thanks a bunch!!

    one more question: the output of Showopen is a number. How do i get the filename?? (same for browse)
     
    elefebvre, Sep 23, 2004
    #12
  13. Check the FileName property. The return value of ShowOpen and Browse
    simply indicates success or failure (any non-zero result is success).
     
    Frank Oquendo, Sep 23, 2004
    #13
  14. elefebvre

    elefebvre Guest

    a file
     
    elefebvre, Sep 24, 2004
    #14
  15. Well Frank's class should work well. If not, here is the straight API code
    that his is probably wrapping in his class.

    -- Mike
    ___________________________
    Mike Tuersley
    CADalyst's CAD Clinic
    Rand IMAGINiT Technologies
    ___________________________
    the trick is to realize that there is no spoon...


    '++++++ BEGIN CODE
    Option Explicit
    Public Const VER_PLATFORM_WIN32s = 0
    Public Const VER_PLATFORM_WIN32_WINDOWS = 1
    Public Const VER_PLATFORM_WIN32_NT = 2

    Public Const OFN_ALLOWMULTISELECT As Long = &H200
    Public Const OFN_CREATEPROMPT As Long = &H2000
    Public Const OFN_ENABLEHOOK As Long = &H20
    Public Const OFN_ENABLETEMPLATE As Long = &H40
    Public Const OFN_ENABLETEMPLATEHANDLE As Long = &H80
    Public Const OFN_EXPLORER As Long = &H80000
    Public Const OFN_EXTENSIONDIFFERENT As Long = &H400
    Public Const OFN_FILEMUSTEXIST As Long = &H1000
    Public Const OFN_HIDEREADONLY As Long = &H4
    Public Const OFN_LONGNAMES As Long = &H200000
    Public Const OFN_NOCHANGEDIR As Long = &H8
    Public Const OFN_NODEREFERENCELINKS As Long = &H100000
    Public Const OFN_NOLONGNAMES As Long = &H40000
    Public Const OFN_NONETWORKBUTTON As Long = &H20000
    Public Const OFN_NOREADONLYRETURN As Long = &H8000& 'see comments
    Public Const OFN_NOTESTFILECREATE As Long = &H10000
    Public Const OFN_NOVALIDATE As Long = &H100
    Public Const OFN_OVERWRITEPROMPT As Long = &H2
    Public Const OFN_PATHMUSTEXIST As Long = &H800
    Public Const OFN_READONLY As Long = &H1
    Public Const OFN_SHAREAWARE As Long = &H4000
    Public Const OFN_SHAREFALLTHROUGH As Long = 2
    Public Const OFN_SHAREWARN As Long = 0
    Public Const OFN_SHARENOWARN As Long = 1
    Public Const OFN_SHOWHELP As Long = &H10
    Public Const OFS_MAXPATHNAME As Long = 260

    'OFS_FILE_OPEN_FLAGS and OFS_FILE_SAVE_FLAGS below
    'are mine to save long statements; they're not
    'a standard Win32 type.
    Public Const OFS_FILE_OPEN_FLAGS = OFN_EXPLORER _
    Or OFN_LONGNAMES _
    Or OFN_CREATEPROMPT _
    Or OFN_NODEREFERENCELINKS

    Public Const OFS_FILE_SAVE_FLAGS = OFN_EXPLORER _
    Or OFN_LONGNAMES _
    Or OFN_OVERWRITEPROMPT _
    Or OFN_HIDEREADONLY

    Public Type OPENFILENAME
    nStructSize As Long
    hWndOwner As Long
    hInstance As Long
    sFilter As String
    sCustomFilter As String
    nMaxCustFilter As Long
    nFilterIndex As Long
    sFile As String
    nMaxFile As Long
    sFileTitle As String
    nMaxTitle As Long
    sInitialDir As String
    sDialogTitle As String
    flags As Long
    nFileOffset As Integer
    nFileExtension As Integer
    sDefFileExt As String
    nCustData As Long
    fnHook As Long
    sTemplateName As String
    pvReserved As Long
    dwReserved As Long
    FlagsEx As Long
    End Type

    Public OFN As OPENFILENAME

    'windows-defined type OSVERSIONINFO
    Public Type OSVERSIONINFO
    OSVSize As Long 'size, in bytes, of this data structure
    dwVerMajor As Long 'ie NT 3.51, dwVerMajor = 3; NT 4.0,
    dwVerMajor = 4.
    dwVerMinor As Long 'ie NT 3.51, dwVerMinor = 51; NT 4.0,
    dwVerMinor= 0.
    dwBuildNumber As Long 'NT: build number of the OS
    'Win9x: build number of the OS in
    low-order word.
    'High-order word contains major & minor
    ver nos.
    PlatformID As Long 'Identifies the operating system
    platform.
    szCSDVersion As String * 128 'NT: string, such as "Service Pack 3"
    'Win9x: 'arbitrary additional
    information'
    End Type

    Public Declare Function GetVersionEx Lib "kernel32" _
    Alias "GetVersionExA" _
    (lpVersionInformation As OSVERSIONINFO) As Long

    Public Declare Function GetOpenFileName Lib "comdlg32" _
    Alias "GetOpenFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long

    Public Declare Function GetSaveFileName Lib "comdlg32" _
    Alias "GetSaveFileNameA" _
    (pOpenfilename As OPENFILENAME) As Long

    Public Declare Function GetShortPathName Lib "kernel32" _
    Alias "GetShortPathNameA" _
    (ByVal lpszLongPath As String, _
    ByVal lpszShortPath As String, _
    ByVal cchBuffer As Long) As Long

    Public Function BrowseFor(sDesc As String, sExt As String, _
    Optional lHwnd As Long, Optional sTitle As
    String) _
    As String
    'used in call setup
    Dim sFilters As String
    'create a string of filters for the dialog
    sFilters = sDesc & vbNullChar & sExt & vbNullChar & vbNullChar

    With OFN
    'size of the OFN structure
    .nStructSize = IIf(IsWin2000Plus(), Len(OFN), Len(OFN) - 12)
    If lHwnd Then
    'window owning the dialog
    .hWndOwner = lHwnd
    End If
    'filters (patterns) for the dropdown combo
    .sFilter = sFilters
    'index to the initial filter
    .nFilterIndex = 2
    'default filename, plus additional padding
    'for the user's final selection(s). Must be
    'double-null terminated
    .sFile = sExt & Space$(1024) & vbNullChar & vbNullChar
    'the size of the buffer
    .nMaxFile = Len(.sFile)
    'default extension applied to
    'file if it has no extention
    .sDefFileExt = sExt & vbNullChar & vbNullChar
    'space for the file title if a single selection
    'made, double-null terminated, and its size
    .sFileTitle = vbNullChar & Space$(512) & vbNullChar & vbNullChar
    .nMaxTitle = Len(OFN.sFileTitle)
    'starting folder, double-null terminated
    .sInitialDir = "c:\" & vbNullChar & vbNullChar
    'the dialog title
    .sDialogTitle = IIf(sTitle <> "", sTitle, "BrowseFor")
    'default open flags and multiselect
    .flags = OFS_FILE_OPEN_FLAGS Or _
    OFN_ALLOWMULTISELECT
    End With
    'call the API
    If GetOpenFileName(OFN) Then BrowseFor = OFN.sFile

    End Function
    Public Function IsWin2000Plus() As Boolean
    'returns True if running Windows 2000 or better
    Dim OSV As OSVERSIONINFO
    OSV.OSVSize = Len(OSV)
    If GetVersionEx(OSV) = 1 Then
    IsWin2000Plus = (OSV.PlatformID = VER_PLATFORM_WIN32_NT) And _
    (OSV.dwVerMajor = 5 And OSV.dwVerMinor >= 0)
    End If
    End Function

    'Make a button called cmdBrowse to test:
    Sub cmdBrowse_Click()
    Dim sFile As String
    'get the file
    sFile = Trim(BrowseFor("ASCII Text file", "*.txt", _
    Me.hwnd, "Select File List"))
    End Sub

    'In the above, you need to add the ability to grab a form's handle
    'if you are using vba. Paste this code into the UserForm:
    Private Declare Function GetActiveWindow Lib "user32" () As Long

    Public Property Get hwnd() As Long
    hwnd = GetActiveWindow()
    End Property


    '++++++ END CODE
     
    Mike Tuersley, Sep 24, 2004
    #15
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.