Author |
Topic: GetOpenFileName (Read 618 times) |
|
CharlesB
New Member
member is offline


Gender: 
Posts: 46
|
 |
GetOpenFileName
« Thread started on: May 1st, 2015, 3:38pm » |
|
As I am trying to learn BBC file handling I came upon this code in the help files. I would like to modify it so that I can direct it to a specific sub-directory.
I would like to incorporate this code into a procedure where it will direct a user to a particular sub-directory and list all of the PDF files. The user can then open any file to read it.
Might I have any assistance on how to do this? Thank you, Charles
Code: dim fs{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
\ lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
\ lpstrFile%, nMaxFile%, lpstrFileTitle%, \
\ nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
\ flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
\ lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
dim fp{t&(260)}
rem ff$ = "BMP files"+chr$0+"*.dat"+chr$0+chr$0
fs.lStructSize% = dim(fs{})
fs.hwndOwner% = @hwnd%
fs.lpstrFilter% = !^ff$
fs.lpstrFile% = fp{}
fs.nMaxFile% = 260
fs.flags% = 6
ff$ = "PDF"+chr$0+"*.pdf"+chr$0+"txt files"+chr$0+"*.txt"+chr$0+chr$0
rem ff$ = "data files"+chr$0+"*.BMP;*.GIF;*.JPG"+chr$0+chr$0
sys "GetOpenFileName", fs{} to result%
if result% filename$ = $$fp{}
|
|
Logged
|
|
|
|
rtr2
Guest
|
 |
Re: GetOpenFileName
« Reply #1 on: May 1st, 2015, 4:25pm » |
|
on May 1st, 2015, 3:38pm, CharlesB wrote:I would like to incorporate this code into a procedure... Might I have any assistance on how to do this? |
|
I would suggest you probably want a function rather than a procedure, since you will be returning information to the calling code (in this case the selected PDF file). Of course you could alternatively use a procedure with a RETURN parameter to get the information back, but if there's just one returned value a function is usually a more straightforward solution.
Putting any code into a function is generally only a topping-and-tailing exercise. You need to add the DEF FN and LOCAL statements at the beginning and the = (end function) at the end:
Code: DEF FNfunction_name(parameters)
LOCAL local_variables, local_structures_etc
REM code to be wrapped in the function......
= returned_value Obviously you need to decide what parameters need to be passed and what value returned, but it sounds as though you have already determined that (your parameter will be the directory you want to be opened initially, and the returned value will be the path to the selected PDF file, if any).
So what difficulties, if any, do you foresee with doing that? The Cross Reference utility will warn you if you have forgotten to make any variables etc. LOCAL so I strongly recommend that you run that.
Incidentally, you have said you wish to force the file selector to open in a particular directory. You may well think that is a reasonable request, and so do I, but Microsoft disagrees! Sadly, they think they know better than you do what directory should be initially selected, and in recent versions of Windows have made it all but impossible to override. See the complicated rules governing exactly how the initial directory is determined here (scroll down to lpstrInitialDir):
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646839.aspx
Richard.
|
|
Logged
|
|
|
|
CharlesB
New Member
member is offline


Gender: 
Posts: 46
|
 |
Re: GetOpenFileName
« Reply #2 on: May 1st, 2015, 7:23pm » |
|
Thank you Richard for this very helpful and "teaching oriented" response. Charles
|
|
Logged
|
|
|
|
|