I've been stuck for the last 8 hours on the use of GetOpenFilename(). I swear this code was working correctly when I first used it about 6 years ago, but now I cannot get multiple file extensions to appear. For saving image files I want BMP, JPG, GIF, etc..., and am including those in the Filter, but only BMP shows up.
The code is below. I've pasted in a printout of the parameters being passed to the routine - why won't the other extensions show up?
The code is below. I've pasted in a printout of the parameters being passed to the routine - why won't the other extensions show up?
Code:
'MODIFIED VERSION OF OpenFileDialog ' ALLOWS OPEN & SAVE BY LAST PARAMETER (0/1) ' OpenFileDialog was originally part of WIN32API.INC & COM32DLG.INC files TYPE OPENFILENAME lStructSize AS LONG hWndOwner AS LONG hInstance AS LONG lpstrFilter AS ASCIIZ PTR lpstrCustomFilter AS ASCIIZ PTR nMaxCustFilter AS LONG nFilterIndex AS LONG lpstrFile AS ASCIIZ PTR nMaxFile AS LONG lpstrFileTitle AS ASCIIZ PTR nMaxFileTitle AS LONG lpstrInitialDir AS ASCIIZ PTR lpstrTitle AS ASCIIZ PTR Flags AS LONG nFileOffset AS INTEGER nFileExtension AS INTEGER lpstrDefExt AS ASCIIZ PTR lCustData AS LONG lpfnHook AS DWORD lpTemplateName AS ASCIIZ PTR END TYPE DECLARE FUNCTION GetOpenFileName LIB "COMDLG32.DLL" ALIAS "GetOpenFileNameA" (lpofn AS OPENFILENAME) AS LONG DECLARE FUNCTION GetSaveFileName LIB "COMDLG32.DLL" ALIAS "GetSaveFileNameA" (lpofn AS OPENFILENAME) AS LONG FUNCTION OpenFileDialog(BYVAL hWnd AS LONG, _ ' parent window BYVAL Caption AS STRING, _ ' caption Filespec AS STRING, _ ' filename BYVAL InitialDir AS STRING, _ ' start directory BYVAL Filter AS STRING, _ ' filename filter BYVAL DefExtension AS STRING, _ ' default extension Flags AS LONG,ibSave AS LONG) AS LONG ' flags & Save=1 LOCAL Ofn AS OPENFILENAME LOCAL zFile AS ASCIIZ * 256 LOCAL zFileTitle AS ASCIIZ * 256 LOCAL zFilter AS ASCIIZ * 512 LOCAL zInitialDir AS ASCIIZ * 256 LOCAL zTitle AS ASCIIZ * 256 LOCAL zDefExt AS ASCIIZ * 10 'code to print out test values 'open "testprint.txt" for output as #1 'PRINT #1,">>>";hWnd;"<<<" 'PRINT #1,">>>";Caption;"<<<" 'PRINT #1,">>>";Filespec;"<<<" 'PRINT #1,">>>";InitialDir;"<<<" 'PRINT #1,">>>";Filter;"<<<" 'PRINT #1,">>>";DefExtension;"<<<" 'PRINT #1,">>>";Flags;"<<<" 'PRINT #1,">>>";ibSave;"<<<" 'close #1 'printout results - >>> and <<< are to show leading and trailing spaces ' >>> 3802330 <<< ' >>>Please Select or Enter a Filename for Save<<< ' >>>RDSimage<<< ' >>>C:\RDS-Win<<< ' >>>Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|Tagged Image File (*.tif)|*.tif|Graphics Exchange Format (*.gif)|*.gif|All Files (*.*)|*.*|<<< ' >>>gif<<< ' >>> 8198 <<< ' >>> 1 <<< REPLACE " " WITH "_" IN Filter 'added 5-08 so that spaces replaced with _ (not needed?) REPLACE "|" WITH CHR$(0) IN Filter IF LEN(InitialDir) = 0 THEN InitialDir = CURDIR$ END IF zFilter = Filter + CHR$(0) zInitialDir = InitialDir + CHR$(0) zFile = Filespec + CHR$(0) zDefExt = DefExtension + CHR$(0) zTitle = Caption + CHR$(0) ofn.lStructSize = SIZEOF(ofn) ofn.hWndOwner = hWnd ofn.lpstrFilter = VARPTR(zFilter) ofn.nFilterIndex = 1 ofn.lpstrFile = VARPTR(zFile) ofn.nMaxFile = SIZEOF(zFile) ofn.lpstrFileTitle = VARPTR(zFileTitle) ofn.nMaxFileTitle = SIZEOF(zFileTitle) ofn.lpstrInitialDir = VARPTR(zInitialDir) IF LEN(zTitle) THEN ofn.lpstrTitle = VARPTR(zTitle) END IF ofn.Flags = Flags ofn.lpstrDefExt = VARPTR(zDefExt) IF ibSave=0 THEN FUNCTION = GetOpenFilename(ofn) ELSE FUNCTION = GetSaveFilename(ofn) END IF Filespec = zFile Flags = ofn.Flags END FUNCTION
Comment