October 26, 2016
Hot Topics:

Using the Common Dialog Open/Save Boxes

  • November 19, 2002
  • By John Percival
  • Send Email »
  • More Articles »

The Flags property can be set, from a selection of the constants below, combined with the Or operator, to allow control over the details of the box. In the demo, there are more. Most of these are supported only by the API calls, so I will leave the description of the important API-only ones until later. Here are the values and a description of their effects, from the VB help file:

cdlOFNAllowMultiselect(&H200)    Specifies that the File Name list box allows multiple selections. The user can select more than one file at run time by pressing the SHIFT key and using the UP ARROW and DOWN ARROW keys to select the desired files. When this is done, the FileName property returns a string containing the names of all selected files. The names in the string are delimited by spaces, because of this, no long filenames can be returned.

cdlOFNCreatePrompt(&H2000)    Specifies that the dialog box prompts the user to create a file that doesn't currently exist. This flag automatically sets the cdlOFNPathMustExist and cdlOFNFileMustExist flags.

cdlOFNExplorer(&H80000)    Use the Explorer-like Open A File dialog box template. Works with Windows 95 and Windows NT 4.0. Do not use with cdlOFNAllowMultiselect.

cdlOFNExtensionDifferent(&H400)    Indicates that the extension of the returned filename is different from the extension specified by the DefaultExt property. This flag isn't set if the DefaultExt property is Null, if the extensions match, or if the file has no extension. This flag value can be checked upon closing the dialog box.

cdlOFNFileMustExist(&H1000)    Specifies that the user can enter only names of existing files in the File Name text box. If this flag is set and the user enters an invalid filename, a warning is displayed. This flag automatically sets the cdlOFNPathMustExist flag.

cdlOFNHelpButton(&H10)    Causes the dialog box to display the Help button. To use this button, set the HelpFile and HelpContext properties of the CommonDialog control prior to showing the dialog.

cdlOFNHideReadOnly(&H4)    Hides the Read Only check box.

cdlOFNLongNames(&H200000)    Use long filenames.

cdlOFNNoChangeDir(&H8)    Forces the dialog box to set the current directory to what it was when the dialog box was opened.

cdlOFNNoDereferenceLinks(&H100000)    Do not dereference shell links (also known as shortcuts). By default, choosing a shell link causes it to be dereferenced by the shell.

cdlOFNNoLongNames(&H40000)    No long file names.

cdlOFNNoReadOnlyReturn(&H8000)    Specifies that the returned file won't have the Read Only attribute set and won't be in a write-protected directory.

cdlOFNNoValidate(&H100)    Specifies that the common dialog box allows invalid characters in the returned filename.

cdlOFNOverwritePrompt(&H2)    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.

cdlOFNPathMustExist(&H800)    Specifies that the user can enter only valid paths. If this flag is set and the user enters an invalid path, a warning message is displayed.

cdlOFNReadOnly(&H1)    Causes the Read Only check box to be initially checked when the dialog box is created. This flag also indicates the state of the Read Only check box when the dialog box is closed.

cdlOFNShareAware(&H4000)    Specifies that sharing violation errors will be ignored.

Lastly, if you are not happy with the standard "Open" title, you can set a new one with the DialogTitle property.

That is it for the OCX method of displaying the dialogs. Remember that almost all of the properties can be set at design-time, so displaying the dialog is as easy as calling one method.

Page 3 of 5

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel