Announcement

Collapse
No announcement yet.

Display openfile/display savefile

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Display openfile/display savefile

    Is it possible to add a second filter line using these commands?

    (e.g. shown in MSWord)

    Bob

  • #2
    Do you mean multiple filters, as explained in the help?
    filter$
    A string expression containing pairs of null-terminated filter strings....
    ...
    Multiple filters can be designated for a single item by separating filter pattern strings with a semicolon:
    Code:
    CHR$("BASIC", 0, "*.BAS;*.INC;*.BAK", 0)
    ??
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      For an example of multiline filters see \PBWin901\Samples\Ddt\Graphic\TextView\TextView.bas
      Code:
        If Len(sPath) = 0 Then sPath = CurDir$
        sFile = "*.BAS;*.INC;*.RC"
       
        Buf = Chr$("PB code files (*.BAS, *.INC, *.RC)", 0, "*.BAS;*.INC;*.RC", 0,  _
                   "Text files (*.TXT)", 0, "*.TXT", 0, _
                   "All files (*.*)", 0, "*.*", 0)
       
        dwStyle = %OFN_Explorer Or %OFN_FileMustExist Or %OFN_HideReadOnly
       
        Display Openfile hDlg, , , "", sPath, buf, "", "BAS", dwStyle To sFile
      Rgds, Dave

      Comment


      • #4
        If you require resizing then add %OFN_ENABLESIZING to dwStyle - we didn't have to with the pre-PB9 methods.

        Comment


        • #5
          If you require resizing then add %OFN_ENABLESIZING to dwStyle - we didn't have to with the pre-PB9 methods
          Huh?

          DISPLAY OPENFILE is new in 9x. By definition new functions cannot have backward-compatibility issues.

          You must be comparing apples and submarines.

          MCM
          Michael Mattias
          Tal Systems (retired)
          Port Washington WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            > - we didn't have to with the pre-PB9 methods.

            Comment


            • #7
              > methods

              What methods? There was no instrinsic "browse for file" function prior to 9x.

              When I need resizeable, I always need OFN_ENABLESIZEING in the flags member of the OPENFILENAME structure. If you don't use that style bit, the common dialogs "GetOpenFileName" and "GetSaveFileName" are not resizeable, as documented, end of discussion.

              Unless you mean the PB-supplied wrapper functions "OpenFileDialog" and "SaveFileDialog" in COMDLG32.INC. But IIRC those use the OPENFILENAME structure, too; they must have just hard-coded that style in there on the assumption you wanted it.

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                > Unless you mean the PB-supplied wrapper functions "OpenFileDialog" and "SaveFileDialog" in COMDLG32.INC.

                Of course I did.

                > But IIRC those use the OPENFILENAME structure, too; they must have just hard-coded that style in there on the assumption you wanted it.

                You did remember correctly, but OFN_ENABLESIZING was not hard-coded into the wrapper functions.

                From Platform SDK:-

                OFN_ENABLESIZING
                Windows 2000/XP, Windows 98/Me: Enables the Explorer-style dialog box to be resized using either the mouse or the keyboard. By default, the Explorer-style Open and Save As dialog boxes allow the dialog box to be resized regardless of whether this flag is set. This flag is necessary only if you provide a hook procedure or custom template. The old-style dialog box does not permit resizing.

                The wrapper functions then got OFN_ENABLESIZING by default.

                I have no idea how Display Openfile/Savefile is coded but one thing is for sure and that is if we don't use %OFN_ENABLESIZING we don't get it; which is, surprise, surprise why I mentioned it.

                Comment


                • #9
                  Looks like the OFN_EXPLORER style handles the 'resizeable.'

                  (I never used those wrapper functions. Like anyone else who had been writing Windows' stuff for a while, I had my own "OpenFileDialog" wrapper function so I was not terribly interested in PB's.)
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment


                  • #10
                    > ... I had my own "OpenFileDialog" wrapper function so I was not terribly interested in PB's.

                    Unless you were doing something fancy then you also got OFN_ENABLESIZING by default and, again if you were not doing anything fancy, you got OFN_EXPLORER by default as well.

                    Comment


                    • #11
                      It's a little long, but her 'tis...

                      USAGE: Copy, paste, modify for this application

                      Code:
                      '   04/19/03 updated filter() in CallOpenSave filename to change to STRING rather
                      '            than ASCIIZ (PB/Win Compiler now *correctly* truncates at first null)
                      '    05/26/03 Changed LpStrFilter to STRPTR
                      '   removed redundant "AS" in REDIM. Made arrays zero based even though element zero
                      '   is not used for efficiency
                      '   03/26/04 Added OPTIONAL ReadOnly for input
                      '   03/31/03 See if I can get Explorer-stule callbacks working.. the EXPLORER-style
                      '            boxes are so much better looking than the 'standard' and when you
                      '            use the hookproc with non-explorer style you get the old "3.1" like boxes
                      '            which are really shitty looking
                      
                      ' required for definition of OpenFileName structure
                      #IF NOT %DEF(%COMDLG32_INC)
                        #INCLUDE "COMDLG32.INC"
                      #ENDIF
                      
                      FUNCTION CallOpenSaveFileName (BYVAL hWnd AS LONG, BYVAL WhichSub AS LONG, OPTIONAL ReadOnly AS LONG)  AS STRING
                         ' hWnd is the owner of the dialog
                         ' WhichSub is %SUB_INPUT_FILE or %SUB_OUTPUT_FILE
                         ' SUB_REPORT_FILE gets an output file with prompt for overwrite.
                         ' Returns: Fully qualifed filename if user selects, or null string if he does not.
                         ' Retains: Last directory searched for each file type
                      
                        STATIC AnyTrip AS LONG
                        STATIC BeenHere() AS LONG          ' have we been here before for this purpose?
                      
                        STATIC OFN() AS OpenFileName       ' save the last choice
                        STATIC Filter() AS STRING, Title() AS ASCIIZ * 48, SearchDir () AS ASCIIZ * %MAX_PATH
                        STATIC FileTitle () AS ASCIIZ * %MAX_PATH  ' the name of the file
                        LOCAL Stat AS LONG, wFullName AS ASCIIZ * %MAX_PATH
                        LOCAL pFullName AS ASCIIZ PTR * %MAX_PATH
                        LOCAL EC AS LONG
                        LOCAL W AS STRING
                        LOCAL AllowReadOnly AS LONG
                      
                      
                        IF ISFALSE (AnyTrip) THEN
                           AnyTrip = %TRUE
                           REDIM OFN(%SUB_GETOPENSAVE_MAX), BeenHere(%SUB_GETOPENSAVE_MAX)
                           REDIM Title     (%SUB_GETOPENSAVE_MAX),_
                                 SearchDir (%SUB_GETOPENSAVE_MAX),_
                                 FileTitle (%SUB_GETOPENSAVE_MAX),_
                                 Filter    (%SUB_GETOPENSAVE_MAX)
                        END IF
                      
                      
                        IF ISFALSE (BeenHere (WhichSub)) THEN
                           BeenHere (WhichSub) = %TRUE
                           OFN(WhichSub).lStructSize       = CDWD(SIZEOF(OFN(WhichSub)))
                           OFN(WhichSub).hInstance         = %NULL
                           OFN(WhichSub).lpstrCustomFilter = %NULL
                           OFN(WhichSub).nMaxCustFilter    = %NULL
                           OFN(WhichSub).nFilterIndex      = 1
                           OFN(WhichSub).lCustData         = 0
                           OFN(WhichSub).lpfnHook          = 0
                           OFN(WhichSub).lpTemplateName    = %NULL
                           OFN(WhichSub).lpstrDefExt       = %NULL
                           OFN(WhichSub).nFileOffset       = 0
                           OFN(WhichSub).nFileExtension    = %NULL
                           SearchDir (WhichSub) = CURDIR$
                           SELECT CASE WhichSub
                                  CASE %SUB_INPUT_FILE
                                       Title (WhichSub)           = "Select Input XML File"
                                       OFN(WhichSub).LpStrTitle   = VARPTR (Title(WhichSub))
                                       Filter(WhichSub)           = "XML (*.xml)" & $NUL & "*.xml" & $NUL & "All Files (*.*)" & $NUL & "*.*" & $NUL & $NUL
                                       OFN(WhichSub).lpStrFilter  = STRPTR (Filter(WhichSub))
                                       ' default flags:
                                       OFN(WhichSub).Flags        =  %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_NOCHANGEDIR
                                       ' 3.25.04 test readonly
                                       ' if param sent and is true, offer option to open read only
                                       ' do not include in here, make this "per trip"
                                        'IF ISTRUE VARPTR (ReadOnly) THEN
                                        '   IF ISTRUE ReadOnly THEN
                                        '       OFN(WhichSub).Flags        =  OfN(WhichSub).flags OR
                      
                                       ' next line test 10/31/02 can we do multi-select without OFN_EXPLORER flag?
                                       ' YES, we CAN
                                      ' OFN(WhichSub).Flags  =  %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_NOCHANGEDIR OR %OFN_ALLOWMULTISELECT
                                       ' next line test 10/31/02 what does OFN_EXPLORER do?
                                       ' new dialog with option to create new folder.
                                       ' BUt.. it appears OFN_EXPLORER flag is automatically put into the save if used for the OPen..
                      
                                      ' OFN(WhichSub).Flags  =  %OFN_FILEMUSTEXIST OR %OFN_HIDEREADONLY OR %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_NOCHANGEDIR OR %OFN_EXPLORER
                                       OFN(WhichSub).LpStrDefExt   = %NULL
                                       OFN(WhichSub).nFilterIndex  = 0&
                                  CASE %SUB_OUTPUT_FILE
                                       Title (WhichSub)            = "Select Tree Report File Name"
                                       OFN(WhichSub).LpStrTitle    = VARPTR (Title(WhichSub))
                                       Filter(WhichSub)            = "Text Files (*.txt)" & $NUL & "*.txt" & $NUL & "All Files (*.*)" & $NUL & "*.*" & $NUL & $NUL
                                       OFN(WhichSub).lpstrFilter   = STRPTR (Filter(WhichSub))
                                       OFN(WhichSub).Flags         = %OFN_LONGNAMES OR %OFN_PATHMUSTEXIST OR %OFN_OVERWRITEPROMPT OR %OFN_HIDEREADONLY OR %OFN_NOCHANGEDIR OR %OFN_EXPLORER
                                       OFN(WhichSub).LpStrDefExt   = %NULL
                                       OFN(WhichSub).nFilterIndex  = 0&
                             END SELECT
                        END IF             ' if this is the first trip for this %SUB_xxxx
                      
                       ' else             ' we've done this browse before; restore the start directory to where we last were...
                        OFN(WhichSub).LpStrInitialDir              = VARPTR(SearchDir(WhichSub))
                      
                        ' set the common stuff which does not vary...
                        FileTitle(WhichSub)              = ""   ' no default filenamme
                        OFN(WhichSub).LpStrFile          = VARPTR (FileTitle(WhichSub))
                        OFN(WhichSub).nMaxFile           = SIZEOF (FileTitle(WhichSub))
                        ' since the owner window may vary for the same sub across calls...
                        OFN(WhichSub).hWndOwner         = hWnd
                      
                        ' Show the read-only box if input and AllowReadonly is true
                      
                      
                        IF WhichSub = %SUB_INPUT_FILE  THEN
                           IF VARPTR(ReadOnly) THEN
                               IF ISTRUE (ReadOnly) THEN
                                 AllowReadOnly = %TRUE
                               END IF
                           END IF
                        END IF
                        ' set the read only flag based on the value for this call
                        IF ISTRUE AllowReadOnly THEN   '
                              ofn(WhichSub).flags =  OFN(WhichSub).flags AND NOT (%OFN_HIDEREADONLY)
                        ELSE
                              ofn(WhichSub).Flags =  ofn(WhichSub).flags OR  %OFN_HIDEREADONLY
                        END IF
                      
                        ' for testing the Explorer hookproc with output file 3/31/04
                        IF WhichSub = %SUB_OUTPUT_FILE THEN
                            ' the read only variable is my "user" value I am going to use for my callback
                            ' NOTE: OFN_ENABLESIZING required when you use a hook proc or the dialog is not resizeable.
                      
                            OFn(WhichSub).flags          = OFN(WhichSub).Flags OR %OFN_EXPLORER OR %OFN_ENABLEHOOK OR %OFN_ENABLESIZING
                            OFN(whichSub).lpfnhook       = CODEPTR (OFNExplorerHookProc)
                            OFN(whichSub).lCustData      = 12345&
                      
                       END IF
                      
                      
                      
                        ' call the API
                        SELECT CASE WhichSub
                           CASE %SUB_INPUT_FILE
                                Stat = GetOpenFileName (OFN(WhichSub))
                           CASE %SUB_OUTPUT_FILE
                              Stat = GetSaveFileName (OFN(WhichSub))
                        END SELECT
                      
                        IF ISTRUE (Stat) THEN
                           W                    = SPACE$(OFN(WhichSub).NMaxFile)
                           pFullName            = OFN(WhichSUb).LpStrFile
                           W                    = @pFullName
                           W                    = TRIM$(W, ANY CHR$(0, &h20))
                           ' set the initial search dir for the next time thru to equal this one
                           SearchDir (WhichSub) = LEFT$(W, INSTR(-1, W, "\"))
                           ' null out the file name for next call to provide consistent search behavior across 9x, NT and 2K:
                           FileTitle(WhichSub)  = ""
                           '
                           IF ISTRUE AllowReadOnly THEN   ' parameter passed, non-zero, input file
                                ReadOnly = (Ofn(whichSub).Flags AND %OFN_READONLY) = %OFN_READONLY  ' set to whatever was chosen
                               ' MSGBOX "Readonly=" & STR$( (Ofn(whichSub).Flags AND %OFN_READONLY) = %OFN_READONLY)
                           END IF
                           FUNCTION = W
                        ELSE
                           LOCAL eCD AS DWORD
                           eCD                  = CommDlgExtendedError
                           IF ECD <> 0 THEN
                              MSGBOX "GetOpen/SaveFileName failed on error#" & STR$(eCD), %MB_APPLMODAL OR %MB_ICONINFORMATION, "Yikes!!!
                           END IF
                           FUNCTION             = ""
                        END IF
                      
                      END FUNCTION
                      MCM
                      Michael Mattias
                      Tal Systems (retired)
                      Port Washington WI USA
                      [email protected]
                      http://www.talsystems.com

                      Comment


                      • #12
                        Sorry for the delay in responding - been driving home across Europe and seeing a new GrandDaughter for the first time en-route. Just got home. Will examine suggestions tomorrow.

                        Bob

                        Comment


                        • #13
                          Originally posted by Robert Wallace View Post
                          ... Will examine suggestions tomorrow.

                          Bob
                          Don't do that. Spend some time thinking about your granddaughter. She'll never be this size again. PB will always be here, hopefully growing as well, but never as cute or precious as granddaughter iis.

                          ====================================
                          "If everything seems under control,
                          you're just not going fast enough."
                          Mario Andretti
                          ====================================
                          Last edited by Gösta H. Lovgren-2; 16 Aug 2009, 09:44 PM.
                          It's a pretty day. I hope you enjoy it.

                          Gösta

                          JWAM: (Quit Smoking): http://www.SwedesDock.com/smoking
                          LDN - A Miracle Drug: http://www.SwedesDock.com/LDN/

                          Comment


                          • #14
                            Dave,

                            Solved the problem for me.

                            Gosta,

                            Infact that is what happened - been broody ever since!

                            Comment

                            Working...
                            X