Results 1 to 7 of 7

Thread: Common Dialog Control

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Houston,TX,USA
    Posts
    4
    I am trying to get DOS 8.3 filenames with
    a Common Dialog Control.

    I have entered the following statements:

    CommonDialog1.Flags = cdlOFNNoLongNames
    CommonDialog1.ShowOpen

    When I get the CommonDialog.Filename
    I get long filenames. Do I have to do
    something else to make this work?

  2. #2
    Guest
    Why don't you just convert it to ShortFileName?

    Code:
    Public Declare Function GetShortPathName _
    Lib "kernel32" Alias "GetShortPathNameA" (ByVal _
    lpszLongPath As String, ByVal lpszShortPath As String, _
    ByVal cchBuffer As Long) As Long
    
    
    Public Function GetShortFilename(ByVal sLongFilename As String) As String
        'Returns the Short Filename associated w
        '     ith sLongFilename
        Dim lRet As Long
        Dim sShortFilename As String
        'First attempt using 1024 character buff
        '     er.
        sShortFilename = String$(1024, " ")
        lRet = GetShortPathName(sLongFilename, sShortFilename, Len(sShortFilename))
        
        'If buffer is too small lRet contains bu
        '     ffer size needed.
    
    
        If lRet > Len(sShortFilename) Then
            'Increase buffer size...
            sShortFilename = String$(lRet + 1, " ")
            'and try again.
            lRet = GetShortPathName(sLongFilename, sShortFilename, Len(sShortFilename))
        End If
        
        'lRet contains the number of characters
        '     returned.
    
    
        If lRet > 0 Then
            GetShortFilename = Left$(sShortFilename, lRet)
        End If

  3. #3
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987

    Thumbs up

    The following code will achieve the effect you are looking for:

    Code:
    Private Sub Form_Load()
        cdl.Filter = "All Files (*.*)|*.*|"
        cdl.Flags = cdlOFNNoLongNames Or cdlOFNAllowMultiselect
        cdl.ShowOpen
    End Sub
    This is the quote from the windows help file (for VB5) that provided the answer


    Under both Windows NT 4.0 and Windows 95 if you do not choose the cdlOFNAllowMultiselect flag, then both the cdlOFNExplorer and cdlOFNLongNames flags have no effect and are essentially the default.
    They don't mention the cdlOFNNoLongNames flag but I tried it and it works, also you have to set a filter or no file names at all will show up.

    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Houston,TX,USA
    Posts
    4

    Thumbs up

    Matthew,

    I tried your routine, and it worked fine.
    Many thanks,

    Don

  5. #5
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    YoungBuck's code is fine as well. Only drawback I see
    is that it list all the files in shortname only and that
    might be a bit of a setback if you are looking for a file
    called adirtbagdogwebsite and you get it listed as adirtb~1.
    (could confuse the user)

    Code:
    Private Sub Form_Load()
        CommonDialog1.Filter = "All Files (*.*)|*.*|"
        CommonDialog1.Flags = cdlOFNNoLongNames Or cdlOFNAllowMultiselect
        CommonDialog1.ShowOpen
        MsgBox CommonDialog1.FileName
     End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Houston,TX,USA
    Posts
    4

    Thumbs up

    YoungBuck, and HeSaidJoe,

    I tried your solution, and they worked well, too.
    However, in this case, I don't want the user to
    have the option of multiple choice.

    I'm certain I can use your solution in future,
    so thanks for the help,

    Don

  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Actually, mine was just an observation.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width