Stuart McLachlan
stuart at lexacorp.com.pg
Thu May 1 05:29:42 CDT 2003
On 1 May 2003 at 10:15, MarkH wrote: > Hello All > > (using AXP on WinXP) > > Does anyone have an example of some open dialog code that allows the > user to select more than one file? I need to be able to select one or > more files and just return the paths to the database, not open them at > that time... > Here's an example of using the GetOpenFileName API yet again :-) You will notice that Flags is set to '%OFN_ALLOWMULTISELECT ( &H00000200), it will do what you want (see the flags section below for explanations and constants). Type OPENFILENAME lStructSize As Long hwndOwner As Long hInstance As Long lpstrFilter As String lpstrCustomFilter As String nMaxCustFilter As Long nFilterIndex As Long lpstrFile As String nMaxFile As Long lpstrFileTitle As String nMaxFileTitle As Long lpstrInitialDir As String lpstrTitle As String flags As Long nFileOffset As Integer nFileExtension As Integer lpstrDefExt As String lCustData As Long lpfnHook As Long lpTemplateName As String End Type Declare Function GetOpenFileName Lib "comdlg32.dll" Alias _ "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long Private Sub btnbrowse_Click() Dim OpenFile As OPENFILENAME Dim lReturn As Long Dim sFilter As String OpenFile.lStructSize = Len(OpenFile) OpenFile.hwndOwner = Me.hwnd OpenFile.hInstance = 0 sFilter = "" & Chr(0) OpenFile.lpstrFilter = sFilter OpenFile.nFilterIndex = 1 OpenFile.lpstrFile = String(257, 0) OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1 OpenFile.lpstrFileTitle = OpenFile.lpstrFile OpenFile.nMaxFileTitle = OpenFile.nMaxFile OpenFile.lpstrInitialDir = "C:\" OpenFile.lpstrTitle = "Select File" OpenFile.flags = &H00000200 lReturn = GetOpenFileName(OpenFile) Text0 = Left$(OpenFile.lpstrFile, InStr(OpenFile.lpstrFile, Chr$(0)) - 1) End Sub Flags A set of bit flags you can use to initialize the dialog box. When the dialog box returns, it sets these flags to indicate the user's input. This member can be a combination of the following flags: OFN_ALLOWMULTISELECT Specifies that the File Name list box allows multiple selections. If you also set the OFN_EXPLORER flag, the dialog box uses the Explorer- style user interface; otherwise, it uses the old-style user interface. If the user selects more than one file, the lpstrFile buffer returns the path to the current directory followed by the filenames of the selected files. The nFileOffset member is the offset to the first filename, and the nFileExtension member is not used. For Explorer-style dialog boxes, the directory and filename strings are NULL separated, with an extra NULL character after the last filename. This format enables the Explorer-style dialogs to return long filenames that include spaces. For old-style dialog boxes, the directory and filename strings are separated by spaces and the function uses short filenames for filenames with spaces. You can use the FindFirstFile function to convert between long and short filenames. If you specify a custom template for an old-style dialog box, the definition of the File Name list box must contain the LBS_EXTENDEDSEL value. OFN_CREATEPROMPT If the user specifies a file that does not exist, this flag causes the dialog box to prompt the user for permission to create the file. If the user chooses to create the file, the dialog box closes and the function returns the specified name; otherwise, the dialog box remains open. OFN_ENABLEHOOK Enables the hook function specified in the lpfnHook member. OFN_ENABLETEMPLATE Indicates that the lpTemplateName member points to the name of a dialog template resource in the module identified by the hInstance member.If the OFN_EXPLORER flag is set, the system uses the specified template to create a dialog box that is a child of the default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to create an old-style dialog box that replaces the default dialog box. OFN_ENABLETEMPLATEHANDLE Indicates that the hInstance member identifies a data block that contains a preloaded dialog box template. The system ignores the lpTemplateName if this flag is specified.If the OFN_EXPLORER flag is set, the system uses the specified template to create a dialog box that is a child of the default Explorer-style dialog box. If the OFN_EXPLORER flag is not set, the system uses the template to create an old-style dialog box that replaces the default dialog box. OFN_EXPLORER Indicates that any customizations made to the Open or Save As dialog box use the new Explorer-style customization methods. For more information, see the "Explorer-Style Hook Procedures" and "Explorer- Style Custom Templates" sections of the Common Dialog Box Library overview.By default, the Open and Save As dialog boxes use the Explorer-style user interface regardless of whether this flag is set. This flag is necessary only if you provide a hook procedure or custom template, or set the OFN_ALLOWMULTISELECT flag. If you want the old- style user interface, omit the OFN_EXPLORER flag and provide a replacement old-style template or hook procedure. If you want the old style but do not need a custom template or hook procedure, simply provide a hook procedure that always returns FALSE. OFN_EXTENSIONDIFFERENT Specifies that the user typed a filename extension that differs from the extension specified by lpstrDefExt. The function does not use this flag if lpstrDefExt is NULL. OFN_FILEMUSTEXIST Specifies that the user can type only names of existing files in the File Name entry field. If this flag is specified and the user enters an invalid name, the dialog box procedure displays a warning in a message box. If this flag is specified, the OFN_PATHMUSTEXIST flag is also used. OFN_HIDEREADONLY Hides the Read Only check box. OFN_LONGNAMES For old-style dialog boxes, this flag causes the dialog box to use long filenames. If this flag is not specified, or if the OFN_ALLOWMULTISELECT flag is also set, old-style dialog boxes use short filenames (8.3 format) for filenames with spaces. Explorer- style dialog boxes ignore this flag and always display long filenames. OFN_NOCHANGEDIR Restores the current directory to its original value if the user changed the directory while searching for files. OFN_NODEREFERENCELINKS Directs the dialog box to return the path and filename of the selected shortcut (.LNK) file. If this value is not given, the dialog box returns the path and filename of the file referenced by the shortcut OFN_NOLONGNAMES For old-style dialog boxes, this flag causes the dialog box to use short filenames (8.3 format). Explorer-style dialog boxes ignore this flag and always display long filenames. OFN_NONETWORKBUTTON Hides and disables the Network button. OFN_NOREADONLYRETURN Specifies that the returned file does not have the Read Only check box checked and is not in a write-protected directory. OFN_NOTESTFILECREATE Specifies that the file is not created before the dialog box is closed. This flag should be specified if the application saves the file on a create-nonmodify network sharepoint. When an application specifies this flag, the library does not check for write protection, a full disk, an open drive door, or network protection. Applications using this flag must perform file operations carefully, because a file cannot be reopened once it is closed. OFN_NOVALIDATE Specifies that the common dialog boxes allow invalid characters in the returned filename. Typically, the calling application uses a hook procedure that checks the filename by using the FILEOKSTRING message. If the text box in the edit control is empty or contains nothing but spaces, the lists of files and directories are updated. If the text box in the edit control contains anything else, nFileOffset and nFileExtension are set to values generated by parsing the text. No default extension is added to the text, nor is text copied to the buffer specified by lpstrFileTitle. If the value specified by nFileOffset is less than zero, the filename is invalid. Otherwise, the filename is valid, and nFileExtension and nFileOffset can be used as if the OFN_NOVALIDATE flag had not been specified. OFN_OVERWRITEPROMPT Causes the Save As dialog box to generate a message box if the selected file already exists. The user must confirm whether to overwrite the file. OFN_PATHMUSTEXIST Specifies that the user can type only valid paths and filenames. If this flag is used and the user types an invalid path and filename in the File Name entry field, the dialog box function displays a warning in a message box. OFN_READONLY Causes the Read Only check box to be checked initially when the dialog box is created. This flag indicates the state of the Read Only check box when the dialog box is closed. OFN_SHAREAWARE Specifies that if a call to the OpenFile function fails because of a network sharing violation, the error is ignored and the dialog box returns the selected filename. If this flag is not set, the dialog box notifies your hook procedure when a network sharing violation occurs for the filename specified by the user. If you set the OFN_EXPLORER flag, the dialog box sends the CDN_SHAREVIOLATION message to the hook procedure. If you do not set OFN_EXPLORER, the dialog box sends the SHAREVISTRING registered message to the hook procedure. OFN_SHOWHELP Causes the dialog box to display the Help button. The hwndOwner member must specify the window to receive the HELPMSGSTRING registered messages that the dialog box sends when the user clicks the Help button.An Explorer-style dialog box sends a CDN_HELP notification message to your hook procedure when the user clicks the Help button. Values of flages are as follows: %OFN_READONLY = &H00000001 %OFN_OVERWRITEPROMPT = &H00000002 %OFN_HIDEREADONLY = &H00000004 %OFN_NOCHANGEDIR = &H00000008 %OFN_SHOWHELP = &H00000010 %OFN_ENABLEHOOK = &H00000020 %OFN_ENABLETEMPLATE = &H00000040 %OFN_ENABLETEMPLATEHANDLE = &H00000080 %OFN_NOVALIDATE = &H00000100 %OFN_ALLOWMULTISELECT = &H00000200 %OFN_EXTENSIONDIFFERENT = &H00000400 %OFN_PATHMUSTEXIST = &H00000800 %OFN_FILEMUSTEXIST = &H00001000 %OFN_CREATEPROMPT = &H00002000 %OFN_SHAREAWARE = &H00004000 %OFN_NOREADONLYRETURN = &H00008000 %OFN_NOTESTFILECREATE = &H00010000 %OFN_NONETWORKBUTTON = &H00020000 %OFN_NOLONGNAMES = &H00040000 ' force no long names for 4.x modules %OFN_EXPLORER = &H00080000 ' new look commdlg %OFN_NODEREFERENCELINKS = &H00100000 %OFN_LONGNAMES = &H00200000 ' force long names for 3.x modules %OFN_ENABLEINCLUDENOTIFY = &H00400000 ' send include message to callback %OFN_ENABLESIZING = &H00800000 %OFN_DONTADDTORECENT = &H02000000 %OFN_FORCESHOWHIDDEN = &H10000000 ' Show All files including System and hidden files %OFN_EX_NOPLACESBAR = &H00000001 ' Return values for the registered message sent to the hook function ' when a sharing violation occurs. %OFN_SHAREFALLTHROUGH allows the ' filename to be accepted, %OFN_SHARENOWARN rejects the name but puts ' up no warning (returned when the app has already put up a warning ' message), and %OFN_SHAREWARN puts up the default warning message ' for sharing violations. ' ' Note: Undefined return values map to OFN_SHAREWARN, but are ' reserved for future use. %OFN_SHAREFALLTHROUGH = 2 %OFN_SHARENOWARN = 1 %OFN_SHAREWARN = 0 -- Lexacorp Ltd http://www.lexacorp.com.pg Information Technology Consultancy, Software Development,System Support.