I repost this forgotten code snippet.
The only problem of the code below is if you move the window the old one remains.
(Somebody is so clever to integrate the above code with this one in order to resolve the "leave trail" problem?)
(I don't know where to post this question..)
Rem Project: FileBox Example © 2002 Dragonfly
Rem Created: 29.09.2002 16:12:04
Rem ***** Main Source File *****
load dll "user32.dll",1
load dll "kernel32.dll",2
load dll "comdlg32.dll",3
set window on
rem Memblock Table
OFN_MB = 1
PathBuffer_MB = 2
FileFilter_MB = 3
FileBoxTitle_MB = 4
rem Offset Table OPENFILENAME Struct
lStructSize = 0
hwndOwner = 4
hInstance = 8
lpstrFilter = 12
lpstrCustomFilter = 16
nMaxCustFilter = 20
nFilterIndex = 24
lpstrFile = 28
nMaxFile = 32
lpstrFileTitle = 36
nMaxFileTitle = 40
lpstrInitialDir = 44
lpstrTitle = 48
Flags = 52
nFileOffset = 56
nFileExtension = 58
lpstrDefExt = 60
lCustData = 64
lpfnHook = 68
lpTemplateName = 72
StructEnd = 76
rem OPENFILENAME Flag Table
OFN_ALLOWMULTISELECT = 0x00000200
OFN_CREATEPROMPT = 0x00002000
OFN_ENABLEHOOK = 0x00000020
OFN_ENABLETEMPLATE = 0x00000040
OFN_ENABLETEMPLATEHANDLE = 0x00000080
OFN_EXPLORER = 0x00080000
OFN_EXTENSIONDIFFERENT = 0x00000400
OFN_FILEMUSTEXIST = 0x00001000
OFN_HIDEREADONLY = 0x00000004
OFN_LONGNAMES = 0x00200000
OFN_NOCHANGEDIR = 0x00000008
OFN_NODEREFERENCELINKS = 0x00100000
OFN_NOLONGNAMES = 0x00040000
OFN_NONETWORKBUTTON = 0x00020000
OFN_NOREADONLYRETURN = 0x00008000
OFN_NOTESTFILECREATE = 0x00010000
OFN_NOVALIDATE = 0x00000100
OFN_OVERWRITEPROMPT = 0x00000002
OFN_PATHMUSTEXIST = 0x00000800
OFN_READONLY = 0x00000001
OFN_SHAREAWARE = 0x00004000
OFN_SHOWHELP = 0x00000010
rem FileBox Info
FileFilter$ = "All Files^*.*^DarkBasic Files^*.dba;*.dbpro^^"
FileBoxTitle$ = "FileBox Example^"
FileBoxFlags = OFN_EXPLORER or OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST or OFN_LONGNAMES
PathBufferSize = 256
hWnd = call dll(1,"GetActiveWindow")
hMod = call dll(2,"GetModuleHandleA",0)
rem Create Memblock Struct
make memblock OFN_MB,StructEnd
make memblock PathBuffer_MB,PathBufferSize
make memblock FileFilter_MB,len(FileFilter$)
make memblock FileBoxTitle_MB,len(FileBoxTitle$)
OFN = get memblock ptr(OFN_MB)
PathBuffer = get memblock ptr(PathBuffer_MB)
FileFilter = get memblock ptr(FileFilter_MB)
FileBoxTitle = get memblock ptr(FileBoxTitle_MB)
rem Dump Strings to Memblock
dump(FileFilter_MB,FileFilter$)
dump(FileBoxTitle_MB,FileBoxTitle$)
rem Write to OPENFILENAME Struct
write memblock dword OFN_MB,lStructSize,StructEnd
write memblock dword OFN_MB,hWndOwner,hWnd
write memblock dword OFN_MB,hInstance,hMod
write memblock dword OFN_MB,lpstrFilter,FileFilter
write memblock dword OFN_MB,lpstrFile,PathBuffer
write memblock dword OFN_MB,nMaxFile,PathBufferSize
write memblock dword OFN_MB,Flags,FileBoxFlags
write memblock dword OFN_MB,lpstrTitle,FileBoxTitle
rem Open FileBox
call dll 3,"GetOpenFileNameA",OFN
print getstr(PathBuffer_MB)
wait key
rem Delete Memblock Struct
delete memblock OFN_MB
delete memblock PathBuffer_MB
delete memblock FileFilter_MB
delete memblock FileBoxTitle_MB
delete dll 1
delete dll 2
delete dll 3
end
function dump(m,s$)
for p=1 to len(s$)
b=asc(mid$(s$,p))
if b=asc("^") then b=0
write memblock byte m,p-1,b
next p
endfunction
function getstr(m)
do
b=memblock byte(m,p)
if b=0 then exit
s$=s$+chr$(b)
inc p
loop
endfunction s$