INFO: Open File Dialog Box -- Pros and Cons

ID: Q74612


The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK)
  • Microsoft Windows Software Development Kit (SDK) 3.1
  • Microsoft Windows 2000


SUMMARY

Applications can call the common dialog library (COMMDLG.DLL) function GetOpenFileName() to retrieve the name of a file that the user wants to manipulate. Using this DLL provides a common interface for opening files across applications and also eliminates dialog-box message processing within the application's code. However, the application must initialize a structure specific to the dialog box. This article discusses the benefits and costs of using the Open File common dialog, via GetOpenFileName().


MORE INFORMATION

When an application uses the Open File dialog box provided by the common dialog DLL, the primary benefit to that application's users will be a familiar interface. Once they learn how to open a file in one application that uses the DLL, they will know how to open a file in all applications that use it.

Features of the Open File dialog include:

  • A list box of files, filtered by extension, in the current directory


  • A list box of directories from root of current drive to current directory, plus subdirectories


  • A combo box of file types to list in filename list box


  • A combo box of drives available, distinguished by drive type


  • An optional "Read Only" check box


  • An optional "Help" button


  • An optional application hook function to modify standard behavior


  • An optional dialog template to add private application features


For the application's programming staff, the benefits of using the Open File common dialog will include:
  • No dialog-box message processing necessary to implement the Open File dialog box


  • Drive and directory listings are constructed by the DLL, not by the application


  • A full pathname for the file to be opened is passed back to the application, and this name can be passed directly to the OpenFile function


  • Offsets into the full pathname are also returned, giving the application access to the filename (sans pathname) and the file extension without the need for parsing


  • The application can pass in its own dialog box template, in which case the DLL will use that template instead of the standard template


  • The application can provide a dialog hook function to extend the interface of the DLL or to change how events are handled


  • The application can choose to have a single filename or multiple filenames returned from the dialog box


The cost for the programming staff could be in adapting previously written application code to handle the common dialog interface. While making this change is straightforward, it does require coding time. If the application only needs a filename with no path, the Open File common dialog is probably not appropriate.

For more information on using the Open File common dialog, query on GetOpenFileName().

Additional query words:

Keywords : kbCmnDlg kbCmnDlgFileO kbCmnDlgSave kbWinOS2000 kbSDKWin32 kbGrpUser
Version : WINDOWS:3.1
Platform : WINDOWS
Issue type : kbinfo


Last Reviewed: January 28, 2000
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.