Global $sSelected = _FileOpenDialogWithPreview("Open with preview", "", "All files (*.*)", "")
ConsoleWrite("!@error = " & @error & @CRLF)
ConsoleWrite("Selected: " & $sSelected & @CRLF)
Func _FileOpenDialogWithPreview($sTitle = "Open", $sInitDir = "", $sFilter = "All Files (*.*)", $sDefaultName = "", $hWnd = 0)
; OPENFILENAME structure:
Local $tOPENFILENAME = DllStructCreate("dword StructSize;" & _
"hwnd Owner;" & _
"ptr Instance;" & _
"ptr Filter;" & _
"ptr CustomFilter;" & _
"dword MaxCustFilter;" & _
"dword FilterIndex;" & _
"ptr File;" & _
"dword MaxFile;" & _
"ptr FileTitle;" & _
"dword MaxFileTitle;" & _
"ptr InitialDir;" & _
"ptr Title;" & _
"dword Flags;" & _
"ushort FileOffset;" & _
"ushort FileExtension;" & _
"ptr DefExt;" & _
"ptr CustData;" & _
"ptr Hook;" & _
"ptr TemplateName;" & _
"ptr Reserved;" & _
"dword SizeReserved;" & _
"dword FlagsEx")
; Set size and owner:
DllStructSetData($tOPENFILENAME, "StructSize", DllStructGetSize($tOPENFILENAME))
DllStructSetData($tOPENFILENAME, "Owner", $hWnd)
; Filter job:
Local $tagFilter
Local $aArray = StringRegExp($sFilter & "|", "\s*(.*?)\s*\((.*?)\)\|", 3)
For $i = 0 To UBound($aArray) - 1
$tagFilter &= "wchar[" & StringLen($aArray[$i]) + 1 & "];"
Next
$tagFilter &= "wchar"
Local $tFilter = DllStructCreate($tagFilter)
For $i = 0 To UBound($aArray) - 1
DllStructSetData($tFilter, $i + 1, $aArray[$i])
Next
DllStructSetData($tOPENFILENAME, "Filter", DllStructGetPtr($tFilter, 1))
; Path job:
Local $tPath = DllStructCreate("wchar[32767]")
DllStructSetData($tPath, 1, $sDefaultName)
DllStructSetData($tOPENFILENAME, "File", DllStructGetPtr($tPath))
DllStructSetData($tOPENFILENAME, "MaxFile", 32767)
; Title job:
Local $tTitle = DllStructCreate("wchar[" & StringLen($sTitle) + 1 & "]")
DllStructSetData($tTitle, 1, $sTitle)
DllStructSetData($tOPENFILENAME, "Title", DllStructGetPtr($tTitle))
; Initial dir job:
Local $tInitDir = DllStructCreate("wchar[" & StringLen($sInitDir) + 1 & "]")
DllStructSetData($tInitDir, 1, $sInitDir)
DllStructSetData($tOPENFILENAME, "InitialDir", DllStructGetPtr($tInitDir))
; Call the function
DllCall("msvfw32.dll", "int", "GetOpenFileNamePreviewW", "ptr", DllStructGetPtr($tOPENFILENAME))
; Get wanted string
Local $sOut = DllStructGetData(DllStructCreate("wchar[32767]", DllStructGetData($tOPENFILENAME, "File")), 1)
Return SetError($sOut = False, 0, $sOut)
EndFunc ;==>_FileOpenDialogWithPreview