Frank O's CommonDialog Class

Discussion in 'AutoCAD' started by Dave F, Feb 4, 2004.

  1. Dave F

    Dave F Guest

    Hi

    I've never used classes before, & I think I'm being a bit on the dim side.
    I've imported the class into a project, but then what?
    Has anybody got an example to get me going?
    Does it need to run from within a form or directly from a module?

    TIA
    Dave F.
     
    Dave F, Feb 4, 2004
    #1
  2. Dave, here's code I use to let the user pick a filename to Save a TIF file
    to. I have this code in a code module that is called from a form's OK
    button.

    James

    ' build TIF filename based on dwg name, sheet and revision, and open
    SaveAs dialog
    Dim strTIFname As String, strTIFpath As String, strTIFtitle As String
    strTIFpath = curdwg.Path
    strTIFtitle = dwgNum & "_" & sheetNum & "_" & revNum & ".tif"
    strTIFname = strTIFpath & "\" & strTIFtitle

    Dim oComDlg As New CommonDialog
    Dim retVal As Long

    Set oComDlg = New CommonDialog
    oComDlg.DefaultExt = "tif"
    oComDlg.DialogTitle = "Save TIF File"
    oComDlg.Filter = "TIF files (*.tif)|*.tif|All files (*.*)|*.*"
    oComDlg.Flags = OFN_OVERWRITEPROMPT
    oComDlg.InitDir = strTIFpath

    'file name (excluding path) and at least 2 NullChar's must fit in
    ..MaxFileSize
    ' or else it will cause an error.
    'if it's too long just use the null filename that oComDlg initialized
    with
    If oComDlg.MaxFileSize - 1 > Len(strTIFtitle) Then
    oComDlg.FileName = strTIFtitle & String(oComDlg.MaxFileSize -
    Len(strTIFtitle), vbNullChar)
    End If

    retVal = oComDlg.ShowSave
    If retVal <= 0 Then 'user cancelled or the API call failed, see
    CommonDialog class
    'restore the printer configuration path to its previous value before
    exiting
    curApp.Preferences.Files.PrinterConfigPath = prevPrintCfgPath
    Exit Sub
    End If
    'get the TIF filename that the user picked
    strTIFname = oComDlg.FileName
    strTIFpath = oComDlg.Path

    Set oComDlg = Nothing 'throw away common dialog
     
    James Belshan, Feb 4, 2004
    #2
  3. Dave F

    Dave F Guest

    Thanks for that James

    I'm trying to find help for the all the flags.
    I don't suppose you know of one?

    TIA

    Dave F.
     
    Dave F, Feb 4, 2004
    #3
  4. James Belshan, Feb 5, 2004
    #4
  5. Dave F

    Dave F Guest

    Another query, if you've the time.

    This seems a bit weird

    I've amended your very helpful example slightly

    The showopen dialog defaults to the normal Win '98+ open dialog.
    But if I add the flag multiselect it displays a really old looking dialog
    (Win 3.1?).

    Do you know if there's a way to avoid this?

    oComDlg.Flags = OFN_ALLOWMULTISELECT

    retVal = oComDlg.ShowOpen

    TIA
    Dave F.
     
    Dave F, Feb 5, 2004
    #5
  6. Don't use the common dialog control then. Use the API instead so you're
    not hampered by old controls. Visit vbnet.com and download one of their
    sample projects to see how to do it.
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 5, 2004
    #6
  7. Dave F

    Dave F Guest

    I may have got the wrong end of the stick, but aren't VBA routines not
    allowed to use the API?

    Cheers
    Dave F.
     
    Dave F, Feb 5, 2004
    #7
  8. I may have got the wrong end of the stick, but aren't VBA routines not
    Dave,
    They are allowed to, and you already are. Frank's CommonDialog.cls is a
    wrapper for the API functions. The first lines the module declare the API
    functions that are used (GetOpenFilename is the one you're calling -- look
    at the ShowOpen function).

    Try this:
    oComDlg.Flags = OFN_EXPLORER Or OFN_ALLOWMULTISELECT

    James
     
    James Belshan, Feb 5, 2004
    #8
  9. Yeah, you've got it flip-flopped. You are allowed to use thhe API but
    not necessarily the controls such as the common dialog. Frank's class
    wraps the API calls for the same API that the common dialog does. There
    are other APIs and approaches to use which is why I directed you to the
    vbnet site.
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 5, 2004
    #9
  10. Dave F

    Dave F Guest

    Thanks, it seems to work.

    Now I just need to work out how to parse the string of multiple files names
    that gets returned.

    Cheers

    Dave F.
     
    Dave F, Feb 5, 2004
    #10
  11. Dave F

    Dave F Guest

    Now I just need to work out how to parse the string of multiple files
    names
    Got it! at http://vbnet.mvps.org
    Hey, you know, I think this internet thing might just catch on! ;-)
     
    Dave F, Feb 5, 2004
    #11
  12. Now I just need to work out how to parse the string of multiple files
    Well, it sounds like you've already got this solved, but FYI, Frank's
    wrapper class has a method that would do this for you, too. Oddly enough,
    it's called ParseFileNames ;-) and will return an array of the filenames.
    I think the first one may be the path, but I'm not sure.

    James
     
    James Belshan, Feb 5, 2004
    #12
  13. Always include OFN_EXPLORER.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Feb 5, 2004
    #13
  14. It's not a control. It's a class module wrapper around the API. The
    problem is the failure to specify the OFN_EXPLORER flag.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Feb 5, 2004
    #14
  15. Not for the OpenFileDialog.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Feb 5, 2004
    #15
  16. ParseFileNames returns an array of fully-qualified paths. The situation
    you described is the default API behavior when querying the selected
    file(s) after a multiple selection.

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com
    (Pull the pin to reply)
     
    Frank Oquendo, Feb 5, 2004
    #16
  17. You're using comdlg32 which is just wrapping the commondialog control.
    Couldn't you also use shell32 and/or kernel32 for files? I know you can
    for folders and I assumed [yeah, I know about assuming<g>] you could for
    files well??? True, you would be making your own control and not using a
    wrapper - but that gets you out from under the eula [if it applies
    here].
    ___________________________
    Mike Tuersley
    CADalyst's AutoCAD Clinic
    Rand IMAGINiT Technologies
     
    Mike Tuersley, Feb 6, 2004
    #17
  18. Dave F

    Dave F Guest

    I'd like to thank all above who've have help me out, & lead me into another
    useful area of VB programming.

    Cheers
    Dave F.
     
    Dave F, Feb 6, 2004
    #18
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.