Date: 02-16-2022
Return to Index
created by gbSnippets
'PowerBASIC has a built-in DDT command to access the Windows file selection dialog
'Primary Code:
'Syntax: DISPLAY OPENFILE [hParent], [xpos], [ypos], title$, folder$, filter$, _
'start$, defaultext$, flags TO filevar$ [,countvar&]
Display OpenFile hParent, 100, 100, title$, folder$, filter$, start$, _
defaultext$, flags& To filevar$, countvar&
'Multiple file selection:
'If the user selects multiple files, and the flag %OFN_ALLOWMULTISELECT is used
'then filevar$ consists of the path Name (which applies all selected files), followed
'by each of the file names of the selected files. Each of these text items are delimited
'in the returned string by a nul - Chr$(0). You can extract each of the multiple names
'with the PARSE$ function or the PARSE statement.
'Flag Options:
%OFN_ALLOWMULTISELECT 'Allow multiple selections. Return values are null-terminated names.
%OFN_CREATEPROMPT 'Allow file which does not exist.
%OFN_ENABLESIZING 'Dialog Is resizable.
%OFN_EXPLORER 'Explorer style interface (default state).
%OFN_FILEMUSTEXIST 'File name must exist.
%OFN_NOCHANGEDIR 'Maintains current directory regardless of user selection.
%OFN_NODEREFERENCELINKS 'Returns name of shortcut file.
%OFN_NONETWORKBUTTON 'Hides and disables the network button.
%OFN_NOTESTFILECREATE 'File not created before the dialog Is closed.
%OFN_NOVALIDATE 'File name not validated For invalid characters.
%OFN_PATHMUSTEXIST 'Allows only valid paths and filenames.
%OFN_SHAREWARE 'Returns network filename even if sharing violation occurs.
%OFN_SHOWHELP 'The Help button is shown
'Compilable Example: (Jose Includes)
'NOTE: see the commented lines for several ways in which to handle file display filters
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
Global hDlg As DWord
Function PBMain() As Long
Local hParent as DWord, title$, folder$, filter$, start$, defaultext$, flags&, filevar$, countvar&
hParent = hDlg 'if not parent, use 0 or %hWnd_Desktop
title$ = "Open File" 'if "", then "Open" is used
folder$ = "c:\" 'if "", then current directory is used
filter$ = Chr$("PowerBASIC", 0, "*.bas", 0) 'same as: "BASIC" + $Nul + "*.bas" + $Nul
'filter$ consists of pairs of $Nul terminated description/pattern values
'filter$ example: Chr$("All Files", 0, "*.*", 0)
'filter$ example: Chr$("BASIC", 0, "*.bas;*.inc;*.bak", 0)
'filter$ example: Chr$("Bitmap Files", 0, "*.bmp", 0, "All Files", 0, "*.*", 0)
start$ = "" 'starting filename
defaultext$ = "bas"
flags& = %OFN_Explorer Or %OFN_FileMustExist Or %OFN_HideReadOnly
Display OpenFile hParent, 100, 100, title$, folder$, filter$, start$, _
defaultext$, flags& To filevar$, countvar&
'filevar$ contains returned name of file selected, "" if no file is selected
'countvar$ contains number of files selected
If Len(filevar$) Then
MsgBox filevar$
Else
MsgBox "No file selected!" 'ESC or Cancel
End If
End Function
'gbs_00118
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm