José,
%OFN_FILEBUFFERSIZE is not found in your latest headers.
James
OFN_FILEBUFFERSIZE does not exist in the C++ SDK headers; it was a PB addition. My wrapper function uses an optional parameter instead.
' ========================================================================================
' Open File Dialog
' It allows both the use of "|" as a separator (for compatibility with legacy code) and
' of nulls, used by PB's DISPLAY OPEN FILE statement.
' bstrFilter = "BASIC|*.BAS;*.INC;*.BI|"
' bstrFilter = CHR$("BASIC", 0, "*.BAS;*.INC;*.BI", 0)
' The minimum buffer is %MAX_PATH and the maximum buffer is unlimited.
' Can not be used with Windows versions below Windows 2000.
' ========================================================================================
FUNCTION AfxOpenFileDialogA ( _
BYVAL hwndOwner AS DWORD _ ' // Parent window
, BYVAL strTitle AS STRING _ ' // Caption
, BYREF strFile AS STRING _ ' // Filename
, BYVAL strInitialDir AS STRING _ ' // Start directory
, BYVAL strFilter AS STRING _ ' // Filename filter
, BYVAL strDefExt AS STRING _ ' // Default extension
, BYREF dwFlags AS DWORD _ ' // Flags
, OPTIONAL BYVAL dwBufLen AS DWORD _ ' // Buffer length
) AS LONG
LOCAL ix AS LONG
LOCAL ofn AS OPENFILENAMEA
' // Filter is a sequence of ASCIIZ strings with a final (extra) $NUL terminator
REPLACE "|" WITH $NUL IN strFilter
strFilter += $NUL
' // If the initial directory has not been specified, assume the current directory
IF LEN(strInitialDir) = 0 THEN strInitialDir = CURDIR$
' // The filename must be null terminated
ix = INSTR(strFile, $NUL)
IF ix THEN strFile = LEFT$(strFile, ix) ELSE strFile = strFile & $NUL
' // The size of the buffer must be at least %MAX_PATH bytes
IF dwBufLen = 0 THEN dwBufLen = 32768 ' // 32 Kb buffer (enough for at least 126 files)
IF dwBufLen < 260 THEN dwBufLen = 260
IF LEN(strFile) < dwBufLen THEN strFile += SPACE$(dwBufLen - LEN(strFile))
' // Fill the members of the structure
IF AfxGetWindowsVersion < 5 THEN
ofn.lStructSize = 76
ELSE
ofn.lStructSize = SIZEOF(ofn)
END IF
ofn.hwndOwner = hwndOwner
ofn.lpstrFilter = STRPTR(strFilter)
ofn.nFilterIndex = 1
ofn.lpstrFile = STRPTR(strFile)
ofn.nMaxFile = LEN(strFile)
ofn.lpstrInitialDir = STRPTR(strInitialDir)
IF LEN(strTitle) THEN
ofn.lpstrTitle = STRPTR(strTitle)
END IF
ofn.Flags = dwFlags
IF LEN(strDefExt) THEN
ofn.lpstrDefExt = STRPTR(strDefExt)
END IF
FUNCTION = GetOpenFilenameA(ofn)
ix = INSTR(strFile, $NUL & $NUL)
IF ix THEN
strFile = LEFT$(strFile, ix - 1)
ELSE
ix = INSTR(strFile, $NUL)
IF ix THEN
strFile = LEFT$(strFile, ix - 1)
ELSE
strFile = ""
END IF
END IF
dwFlags = ofn.Flags
END FUNCTION
' ========================================================================================
' ========================================================================================
FUNCTION AfxOpenFileDialogW ( _
BYVAL hwndOwner AS DWORD _ ' // Parent window
, BYVAL bstrTitle AS WSTRING _ ' // Caption
, BYREF bstrFile AS WSTRING _ ' // Filename
, BYVAL bstrInitialDir AS WSTRING _ ' // Start directory
, BYVAL bstrFilter AS WSTRING _ ' // Filename filter
, BYVAL bstrDefExt AS WSTRING _ ' // Default extension
, BYREF dwFlags AS DWORD _ ' // Flags
, OPTIONAL BYVAL dwBufLen AS DWORD _ ' // Buffer length
) AS LONG
LOCAL ix AS LONG
LOCAL ofn AS OPENFILENAMEW
' // Filter is a sequence of ASCIIZ strings with a final (extra) $NUL terminator
REPLACE "|" WITH $NUL IN bstrFilter
bstrFilter += $$NUL
' // If the initial directory has not been specified, assume the current directory
IF LEN(bstrInitialDir) = 0 THEN bstrInitialDir = CURDIR$
' // The filename must be null terminated
ix = INSTR(bstrFile, $NUL)
IF ix THEN bstrFile = LEFT$(bstrFile, ix) ELSE bstrFile = bstrFile & $NUL
' // The size of the buffer must be at least %MAX_PATH bytes
IF dwBufLen = 0 THEN dwBufLen = 32768 ' // 32 Kb buffer (enough for at least 126 files)
IF dwBufLen < 260 THEN dwBufLen = 260
IF LEN(bstrFile) < dwBufLen THEN bstrFile += SPACE$(dwBufLen - LEN(bstrFile))
' // Fill the members of the structure
IF AfxGetWindowsVersion < 5 THEN
ofn.lStructSize = 76
ELSE
ofn.lStructSize = SIZEOF(ofn)
END IF
ofn.hwndOwner = hwndOwner
ofn.lpstrFilter = STRPTR(bstrFilter)
ofn.nFilterIndex = 1
ofn.lpstrFile = STRPTR(bstrFile)
ofn.nMaxFile = LEN(bstrFile)
ofn.lpstrInitialDir = STRPTR(bstrInitialDir)
IF LEN(bstrTitle) THEN
ofn.lpstrTitle = STRPTR(bstrTitle)
END IF
ofn.Flags = dwFlags
IF LEN(bstrDefExt) THEN
ofn.lpstrDefExt = STRPTR(bstrDefExt)
END IF
FUNCTION = GetOpenFilenameW(ofn)
ix = INSTR(bstrFile, $NUL & $NUL)
IF ix THEN
bstrFile = LEFT$(bstrFile, ix - 1)
ELSE
ix = INSTR(bstrFile, $NUL)
IF ix THEN
bstrFile = LEFT$(bstrFile, ix - 1)
ELSE
bstrFile = ""
END IF
END IF
dwFlags = ofn.Flags
END FUNCTION
' ========================================================================================
#IF %DEF(%UNICODE)
MACRO AfxOpenFileDialog = AfxOpenFileDialogW
MACRO OpenFileDialog = AfxOpenFileDialogW
#ELSE
MACRO AfxOpenFileDialog = AfxOpenFileDialogA
MACRO OpenFileDialog = AfxOpenFileDialogA
#ENDIF
Alternatively, you can use the CAfxDialog class.
LOCAL pofd AS IAfxFileDialog
pofd = CLASS "CAfxFileDialog"
IF ISNOTHING(pofd) THEN EXIT SUB
pofd.DefaultFolder = CURDIR$
pofd.FileName = "*.BAS;*.INC"
pofd.DefaultExtension = "BAS"
pofd.Filter = CHR$("PB Code Files (*.BAS)", 0, "*.BAS", 0) & _
CHR$("PB Include Files (*.INC)", 0, "*.INC", 0) & _
CHR$("PB Template Files (*.PBTPL)", 0, "*.PBTPL", 0) & _
CHR$("All Files (*.*)", 0, "*.*", 0)
pofd.Options = %OFN_EXPLORER OR %OFN_FILEMUSTEXIST OR %OFN_ALLOWMULTISELECT
pofd.BufLen = 65536
IF pofd.ShowOpenDialog THEN
LOCAL pFiles AS IPowerCollection
LOCAL vFile AS VARIANT
pFiles = pofd.Files
? "Selected path: " & pofd.SelectedPath
FOR EACH vFile IN pFiles
? VARIANT$$(vFile)
NEXT
END IF