hi Petr
I will checkout your link asap, but first here's the demo with corrections to the FILEDIALOGTYPE structure
' Dialog flag constants (use + or OR to use more than 1 flag value)
CONST OFN_ALLOWMULTISELECT = &H200& ' Allows the user to select more than one file, not recommended!
CONST OFN_CREATEPROMPT = &H2000& ' Prompts if a file not found should be created(GetOpenFileName only).
CONST OFN_EXTENSIONDIFFERENT = &H400& 'Allows user to specify file extension other than default extension.
CONST OFN_FILEMUSTEXIST = &H1000& ' Chechs File name exists(GetOpenFileName only).
CONST OFN_HIDEREADONLY = &H4& ' Hides read-only checkbox(GetOpenFileName only)
CONST OFN_NOCHANGEDIR = &H8& ' Restores the current directory to original value if user changed
CONST OFN_NODEREFERENCELINKS = &H100000& 'Returns path and file name of selected shortcut(.LNK) file instead of file referenced.
CONST OFN_NONETWORKBUTTON = &H20000& ' Hides and disables the Network button.
CONST OFN_NOREADONLYRETURN = &H8000& ' Prevents selection of read-only files, or files in read-only subdirectory.
CONST OFN_NOVALIDATE = &H100& ' Allows invalid file name characters.
CONST OFN_OVERWRITEPROMPT = &H2& ' Prompts if file already exists(GetSaveFileName only)
CONST OFN_PATHMUSTEXIST = &H800& ' Checks Path name exists (set with OFN_FILEMUSTEXIST).
CONST OFN_READONLY = &H1& ' Checks read-only checkbox. Returns if checkbox is checked
CONST OFN_SHAREAWARE = &H4000& ' Ignores sharing violations in networking
CONST OFN_SHOWHELP = &H10& ' Shows the help button (useless!)
'--------------------------------------------------------------------------------------------
DEFINT A-Z
TYPE FILEDIALOGTYPE
lStructSize AS LONG ' For the DLL call
hwndOwner AS _OFFSET ' Dialog will hide behind window when not set correctly
hInstance AS _OFFSET ' Handle to a module that contains a dialog box template.
lpstrFilter AS _OFFSET ' Pointer of the string of file filters
lpstrCustFilter AS _OFFSET
nMaxCustFilter AS LONG
nFilterIndex AS LONG ' One based starting filter index to use when dialog is called
lpstrFile AS _OFFSET ' String full of 0's for the selected file name
nMaxFile AS LONG ' Maximum length of the string stuffed with 0's minus 1
lpstrFileTitle AS _OFFSET ' Same as lpstrFile
nMaxFileTitle AS LONG ' Same as nMaxFile
lpstrInitialDir AS _OFFSET ' Starting directory
lpstrTitle AS _OFFSET ' Dialog title
flags AS LONG ' Dialog flags
nFileOffset AS INTEGER ' Zero-based offset from path beginning to file name string pointed to by lpstrFile
nFileExtension AS INTEGER ' Zero-based offset from path beginning to file extension string pointed to by lpstrFile.
lpstrDefExt AS _OFFSET ' Default/selected file extension
lCustData AS _INTEGER64
lpfnHook AS _UNSIGNED _OFFSET
lpTemplateName AS _OFFSET
END TYPE
DECLARE DYNAMIC LIBRARY "comdlg32" ' Library declarations using _OFFSET types
FUNCTION GetOpenFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Open file dialog
FUNCTION GetSaveFileNameA& (DIALOGPARAMS AS FILEDIALOGTYPE) ' The Save file dialog
END DECLARE
DECLARE LIBRARY
FUNCTION FindWindow~&& (BYVAL ClassName AS _OFFSET, WindowName$) ' To get hWnd handle
END DECLARE
_TITLE "FOCdemo" 'set Title of program
'DIM hWnd AS _UNSIGNED _INTEGER64
hWnd%& = _WINDOWHANDLE 'FindWindow(0, "Open and Save Dialog demo" + CHR$(0)) 'get window handle using _TITLE string
'hWnd~&& = FindWindow(0, "FOCdemo" + CHR$(0)) 'get window handle using _TITLE string
PRINT hWnd%&
' Do the Open File dialog call!
Filter$ = "Batch files (*.bat)|*.BAT|JPEG images (*.jpg)|*.JPG|All files (*.*)|*.*"
Flags& = OFN_FILEMUSTEXIST + OFN_NOCHANGEDIR + OFN_READONLY ' add flag constants here
OFile$ = GetOpenFileName$("YEAH! Common Dialogs in QB64!!!", ".\", Filter$, 1, Flags&, hWnd%&)
IF OFile$ = "" THEN ' Display Open dialog results
PRINT "Shame on you! You didn't pick any file..."
ELSE
PRINT "You picked this file: "
PRINT OFile$
IF (Flags& AND OFN_READONLY) THEN PRINT "Read-only checkbox checked." 'read-only value in return
END IF
_DELAY 5 ' Do the Save File dialog call!
Filter$ = "Basic files (*.bas)|*.BAS|All files (*.*)|*.*"
Flags& = OFN_OVERWRITEPROMPT + OFN_NOCHANGEDIR ' add flag constants here
SFile$ = GetSaveFileName$("Save will not create a file!!!", ".\", Filter$, 1, Flags&, hWnd%&)
IF SFile$ = "" THEN ' Display Save dialog results
PRINT "You didn't save the file..."
ELSE
PRINT "You saved this file: "
PRINT SFile$
END IF
END
FUNCTION GetOpenFileName$ (Title$, InitialDir$, Filter$, FilterIndex, Flags&, hWnd%&)
' Title$ - The dialog title.
' InitialDir$ - If this left blank, it will use the directory where the last opened file is
' located. Specify ".\" if you want to always use the current directory.
' Filter$ - File filters separated by pipes (|) in the same format as using VB6 common dialogs.
' FilterIndex - The initial file filter to use. Will be altered by user during the call.
' Flags& - Dialog flags. Will be altered by the user during the call.
' hWnd& - Your program's window handle that should be aquired by the FindWindow function.
'
' Returns: Blank when cancel is clicked otherwise, the file name selected by the user.
' FilterIndex and Flags& will be changed depending on the user's selections.
DIM OpenCall AS FILEDIALOGTYPE ' Needed for dialog call
fFilter$ = Filter$
FOR R = 1 TO LEN(fFilter$) ' Replace the pipes with character zero
IF MID$(fFilter$, R, 1) = "|" THEN MID$(fFilter$, R, 1) = CHR$(0)
NEXT R
fFilter$ = fFilter$ + CHR$(0)
lpstrFile$ = STRING$(2048, 0) ' For the returned file name
lpstrDefExt$ = STRING$(10, 0) ' Extension will not be added when this is not specified
OpenCall.lStructSize = LEN(OpenCall)
OpenCall.hwndOwner = hWnd%&
OpenCall.lpstrFilter = _OFFSET(fFilter$)
OpenCall.nFilterIndex = FilterIndex
OpenCall.lpstrFile = _OFFSET(lpstrFile$)
OpenCall.nMaxFile = LEN(lpstrFile$) - 1
OpenCall.lpstrFileTitle = OpenCall.lpstrFile
OpenCall.nMaxFileTitle = OpenCall.nMaxFile
OpenCall.lpstrInitialDir = _OFFSET(InitialDir$)
OpenCall.lpstrTitle = _OFFSET(Title$)
OpenCall.lpstrDefExt = _OFFSET(lpstrDefExt$)
OpenCall.flags = Flags&
Result = GetOpenFileNameA&(OpenCall) ' Do Open File dialog call!
IF Result THEN ' Trim the remaining zeros
GetOpenFileName$ = LEFT$(lpstrFile$, INSTR(lpstrFile$, CHR$(0)) - 1)
Flags& = OpenCall.flags
FilterIndex = OpenCall.nFilterIndex
END IF
END FUNCTION
FUNCTION GetSaveFileName$ (Title$, InitialDir$, Filter$, FilterIndex, Flags&, hWnd%&)
' Title$ - The dialog title.
' InitialDir$ - If this left blank, it will use the directory where the last opened file is
' located. Specify ".\" if you want to always use the current directory.
' Filter$ - File filters separated by pipes (|) in the same format as VB6 common dialogs.
' FilterIndex - The initial file filter to use. Will be altered by user during the call.
' Flags& - Dialog flags. Will be altered by the user during the call.
' hWnd& - Your program's window handle that should be aquired by the FindWindow function.
' Returns: Blank when cancel is clicked otherwise, the file name entered by the user.
' FilterIndex and Flags& will be changed depending on the user's selections.
DIM SaveCall AS FILEDIALOGTYPE ' Needed for dialog call
fFilter$ = Filter$
FOR R = 1 TO LEN(fFilter$) ' Replace the pipes with zeros
IF MID$(fFilter$, R, 1) = "|" THEN MID$(fFilter$, R, 1) = CHR$(0)
NEXT R
fFilter$ = fFilter$ + CHR$(0)
lpstrFile$ = STRING$(2048, 0) ' For the returned file name
lpstrDefExt$ = STRING$(10, 0) ' Extension will not be added when this is not specified
SaveCall.lStructSize = LEN(SaveCall)
SaveCall.hwndOwner = _OFFSET(hWnd%&)
SaveCall.lpstrFilter = _OFFSET(fFilter$)
SaveCall.nFilterIndex = FilterIndex
SaveCall.lpstrFile = _OFFSET(lpstrFile$)
SaveCall.nMaxFile = LEN(lpstrFile$) - 1
SaveCall.lpstrFileTitle = SaveCall.lpstrFile
SaveCall.nMaxFileTitle = SaveCall.nMaxFile
SaveCall.lpstrInitialDir = _OFFSET(InitialDir$)
SaveCall.lpstrTitle = _OFFSET(Title$)
SaveCall.lpstrDefExt = _OFFSET(lpstrDefExt$)
SaveCall.flags = Flags&
Result& = GetSaveFileNameA&(SaveCall) ' Do dialog call!
IF Result& THEN ' Trim the remaining zeros
GetSaveFileName$ = LEFT$(lpstrFile$, INSTR(lpstrFile$, CHR$(0)) - 1)
Flags& = SaveCall.flags
FilterIndex = SaveCall.nFilterIndex
END IF
END FUNCTION
I am fairly confident that it's acceptably accurate, I printed out the types and sizes in FB
however, it doesn't work