First up is the include file. Save this as FileReq_Include.dba.
Rem *** Include File: FileReq_Include.dba ***
Rem Created with Patch 3.1
remstart
REQUIREMENTS:
1) reqptr as REQUESTER_PTRDATA and InitFileReq() should both be placed
at the top of your program.
2) Handles.dll in the `\Compiler\plugins-user` folder. This can be found at
http://www.nickk.nildram.co.uk/ under DBPro plugins.
LIMITATIONS:
1) Cannot be used in Fullscreen Exclusive Mode. You won't see anything if
you try because the requester will open behind these displays, if that
happens then press the Escape key to cancel the requester.
2) Moving the requester will upset the DBPro display underneath it until
the next SYNC/FASTSYNC call. A bit annoying that.
TIPS:
1) If/When your program exists properly don't forget to call
UnloadFileReq() to free up areas of memory.
remend
#CONSTANT MAXSTRINGSIZE 256
TYPE REQUESTER_PTRDATA
DllNumber as integer
ptrRequester as dword
ptrFilter as dword
ptrCustomFilter as dword
ptrFile as dword
ptrFileTitle as dword
ptrInitialDir as dword
ptrTitle as dword
ptrDefExt as dword
ptrTemplateName as dword
ENDTYPE
` ---------------------------------------------------------------------------
Function InitFileReq(DllNum)
` DllNum = an unused dll number for Comdlg32.dll (1 - 255)
reqptr.DllNumber = DllNum
load dll "Comdlg32.dll",reqptr.DllNumber
if dll exist(reqptr.DllNumber)
rem --- store memory pointers
reqptr.ptrRequester = make memory(80)
reqptr.ptrFilter = make memory(MAXSTRINGSIZE)
reqptr.ptrCustomFilter = make memory(MAXSTRINGSIZE)
reqptr.ptrFile = make memory(MAXSTRINGSIZE)
reqptr.ptrFileTitle = make memory(MAXSTRINGSIZE)
reqptr.ptrInitialDir = make memory(MAXSTRINGSIZE)
reqptr.ptrTitle = make memory(MAXSTRINGSIZE)
reqptr.ptrDefExt = make memory(MAXSTRINGSIZE)
reqptr.ptrTemplateName = make memory(MAXSTRINGSIZE)
rem --- set values in memory (ptrRequester)
SetReqLongValue(0,76)
SetReqLongValue(3,reqptr.ptrFilter)
SetReqLongValue(4,reqptr.ptrCustomFilter)
SetReqLongValue(5,255)
SetReqLongValue(6,0)
SetReqLongValue(7,reqptr.ptrFile)
SetReqLongValue(8,255)
SetReqLongValue(9,reqptr.ptrFileTitle)
SetReqLongValue(10,255)
SetReqLongValue(11,reqptr.ptrInitialDir)
SetReqLongValue(12,reqptr.ptrTitle)
SetReqLongValue(13,0)
else
set current bitmap 0 : cls rgb(0,0,0) : ink rgb(255,255,255),0
print "Unable to load Comdlg32.dll"
print "Press any key to exit."
sync : wait key : end
endif
endfunction
function UnloadFileReq()
rem --- erase memory
delete memory reqptr.ptrRequester
delete memory reqptr.ptrFilter
delete memory reqptr.ptrCustomFilter
delete memory reqptr.ptrFile
delete memory reqptr.ptrFileTitle
delete memory reqptr.ptrInitialDir
delete memory reqptr.ptrTitle
delete memory reqptr.ptrDefExt
delete memory reqptr.ptrTemplateName
delete dll reqptr.DllNumber
endfunction
` ---------------------------------------------------------------------------
function StringToMemory(ptr,s$,zerochr$)
fill memory ptr, 0, MAXSTRINGSIZE
if len(s$) = 0 then exitfunction 0
if zerochr$="" then zero = 0 else zero = asc(zerochr$)
bt as byte
index = 1
repeat
bt = asc(mid$(s$,index))
if bt <> zero then *ptr = bt
inc index,1 : inc ptr,1
until index > len(s$) or index = MAXSTRINGSIZE
endfunction 1
` ---------------------------------------------------------------------------
function ReadMemoryString(ptr)
bt as byte
s$ = "" : index = 1
repeat
bt = *ptr
if bt > 0 then s$ = s$ + chr$(bt)
inc index,1 : inc ptr,1
until bt = 0 or index = MAXSTRINGSIZE
endfunction s$
` ---------------------------------------------------------------------------
function SetReqLongValue(pos, v as dword)
ptr as dword
ptr = reqptr.ptrRequester + (pos * 4)
*ptr = v
endfunction
` ---------------------------------------------------------------------------
function PrepareReq(title$,path$,filter$)
StringToMemory(reqptr.ptrTitle, title$, "")
if path$="" or StringToMemory(reqptr.ptrInitialDir, path$, "")= 0
StringToMemory(reqptr.ptrInitialDir, "C:\", "")
endif
if filter$="" or StringToMemory(reqptr.ptrFilter, filter$, "|")= 0
StringToMemory(reqptr.ptrFilter, "All Files (*.*)|*.*", "|")
endif
` StringToMemory(reqptr.ptrCustomFilter, "", "")
StringToMemory(reqptr.ptrFile, space$(254), "")
StringToMemory(reqptr.ptrFileTitle, space$(254), "")
` SetReqLongValue(1, 0)
SetReqLongValue(1, getHWND())
SetReqLongValue(2, getHINSTANCE())
endfunction
function FileReqOpen(title$,path$,filter$)
PrepareReq(title$,path$,filter$)
r = call dll(reqptr.DllNumber, "GetOpenFileNameA", reqptr.ptrRequester)
endfunction r
function FileReqSave(title$,path$,filter$)
PrepareReq(title$,path$,filter$)
r = call dll(reqptr.DllNumber, "GetSaveFileNameA", reqptr.ptrRequester)
endfunction r
` ---------------------------------------------------------------------------
function ReqFileName()
f$ = ReadMemoryString(reqptr.ptrFile)
endfunction f$
function ReqFileTitle()
f$ = ReadMemoryString(reqptr.ptrFileTitle)
endfunction f$
function ReqFolderName()
fn$ = ReqFileName() : ft$ = ReqFileTitle()
f$ = left$(fn$,len(fn$) - len(ft$))
endfunction f$
Now a small demo. Run this in any Windowed display.
Remember! Add FileReq_Include.dba in the Included Source Files list.
sync on : sync rate 60
rem --- Iniatialise requester
reqptr as REQUESTER_PTRDATA
InitFileReq(1)
r = FileReqOpen("DBPro Open File","C:\","Text Files (*.txt)|*.txt|All Files (*.*)|*.*|")
if r
ink rgb(255,255,0),0 : print "Full Open File Name:"
ink rgb(255,255,255),0 : print ReqFileName()
print
ink rgb(255,255,0),0 : print "Selected Folder Name:"
ink rgb(255,255,255),0 : print ReqFolderName()
print
ink rgb(255,255,0),0 : print "File Title:"
ink rgb(255,255,255),0 : print ReqFileTitle()
else
ink rgb(255,128,0),0 : print "User canceled Open File"
endif
sync
print : print
r = FileReqSave("DBPro Save File","C:\","Text Files (*.txt)|*.txt|All Files (*.*)|*.*|")
if r
ink rgb(0,255,255),0 : print "Full Save File Name:"
ink rgb(255,255,255),0 : print ReqFileName()
print
ink rgb(0,255,255),0 : print "Selected Folder Name:"
ink rgb(255,255,255),0 : print ReqFolderName()
print
ink rgb(0,255,255),0 : print "File Title:"
ink rgb(255,255,255),0 : print ReqFileTitle()
else
ink rgb(255,128,0),0 : print "User canceled Save File"
endif
sync : wait key
rem --- clean up requester and exit
UnloadFileReq()
end
The major problem with this is when you move or resize the requester, it screws up the DBPro display until you exit the requester and call the next SYNC/FASTSYNC. Unfortunatly I don't think it's possible to solve this. pity.
Unless, one of you boffins knows a way of locking the requester in the center of the display without resizing. That would be a good compromise.
Programming anything is an art, and you can't rush art.
Unless your name is Bob Ross, then you can do it in thirty minutes.