PRB: Default Extension Ignores File Type in VB Common DialogLast reviewed: November 17, 1995Article ID: Q106682 |
The information in this article applies to:
SYMPTOMSThe common dialog custom control (CMDIALOG.VBX) cannot determine which file type you choose in the Open or Save As dialog box under List Files of Type. Your chosen file type correctly displays existing files of that type and filters out other files. However, Visual Basic code cannot detect which file type you chose. Also, the default file name extension set by the DefaultExt property is not affected by changes you make under List Files of Type. As a result, a file name that you enter without an extension will take the extension of DefaultExt instead of your choice under List Files of Type. The above behavior of File Open and File Save As is different from many other Windows applications, such as Microsoft Excel. Excel determines which file-type filter you choose and automatically appends that extension to any file name that you may enter without an extension.
CAUSEThis behavior is by design in the common dialog control in Visual Basic.
WORKAROUNDInstead of using Visual Basic's common dialog custom control, you can write your own DLL routine in C to call the Windows common dialog routines located in COMMDLG.DLL. Then you can call that DLL from Visual Basic.
STATUSThis behavior is by design. A change in the design is under review and will be considered for inclusion in a future release.
MORE INFORMATIONNOTE: In Visual Basic 4.0, the common dialog's name property must be changed from CommonDialog1 to CMDialog1.
Steps to Reproduce Behavior
Workaround for Windows API ProgrammersVisual Basic's common dialog custom controls for Open and Save As pass their FilterIndex property to the Windows API function GetOpenFileName. GetOpenFileName is located in the Windows COMMDLG.DLL file. However, Visual Basic ignores the nFilterIndex value that the GetOpenFileName function returns. By design, your Visual Basic program cannot access the structure returned by the GetOpenFileName function, even by calling API routines. You can write your own DLL routine in C to call the Windows common dialog routines located in COMMDLG.DLL. Then call this DLL from Visual Basic. The following documentation from the Windows Software Development Kit (SDK) explains how to use the nFilterIndex element of the structure passed to GetOpenFileName:
nFilterIndex: Specifies an index into the buffer pointed to by the lpstrFiler member. The system uses the index value to obtain a pair of strings to use as the initial filter description and filter pattern for the dialog box. The first pair of strings has an index value of 1. When the user chooses the OK button to close the dialog box, the system copies the index of the selected filter strings into this location. If the nFilterIndex member is 0, the filter in the buffer pointed to by the lpstrCustomFilter member is used. If the nFilterIndex member is 0 and the lpstrCustomFilter member is NULL, the system uses the first filter in the buffer pointed to by the lpstrFilter member. If each of the three members is either 0 or NULL, the system does not use any filters and does not show any files in the File Name list box of the dialog box. |
Additional reference words: 2.00 3.00 4.00 vb416 vb4win
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |