10
20
30 :
40 KeyRoot$="Software\J.G.Harston\Demos\SpoonFeed3\"
50 DIM fs{lStructSize%, hwndOwner%, hInstance%, lpstrFilter%, \
60 \ lpstrCustomFilter%, nMaxCustFilter%, nFilterIndex%, \
70 \ lpstrFile%, nMaxFile%, lpstrFileTitle%, \
80 \ nMaxFileTitle%, lpstrInitialDir%, lpstrTitle%, \
90 \ flags%, nFileOffset{l&,h&}, nFileExtension{l&,h&}, \
100 \ lpstrDefExt%, lCustData%, lpfnHook%, lpTemplateName%}
110 DIM fp{t&(260)}
120 load$="":save$=""
130 :
140 REPEAT:CLS:PRINT"SpoonFeed 3"''"Press:"
150 PRINT"1: Load a file"'"2: Save a file"'"0: Exit"'
160 IFload$<>"":PRINT"Last loaded: ";load$
170 IFsave$<>"":PRINT"Last saved: ";save$
180 REPEAT:K$=GET$:UNTILINSTR("012",K$)
190 IF K$="1":load$=FNFile_Open("Load a file")
200 IF K$="2":save$=FNFile_Save("Save a file")
210 UNTIL K$="0":QUIT
220 :
230 DEFFNFile_Open(ft$)
240 ft$=ft$+CHR$0
250 LastLoad$=FNReg_Rd(KeyRoot$+"LastLoad")+CHR$0
260 ff$="All files"+CHR$0+"*.*"+CHR$0+CHR$0
270 $$fp{}=LastLoad$
280 fs.lStructSize% = DIM(fs{})
290 fs.hwndOwner% = @hwnd%
300 fs.lpstrFilter% = !^ff$
310 fs.lpstrInitialDir% = !^LastLoad$
320 fs.lpstrFile% = fp{}
330 fs.nMaxFile% = 260
340 fs.lpstrTitle% = !^ft$
350 fs.flags% = 6
360 SYS "GetOpenFileName", fs{} TO result%
370 IF result%:ff$=$$fp{}:PROCReg_Wr(KeyRoot$+"LastLoad",ff$):=ff$
380 =""
390 :
400 DEFFNFile_Save(ft$)
410 ft$=ft$+CHR$0
420 LastSave$=FNReg_Rd(KeyRoot$+"LastSave")+CHR$0
430 ff$="All files"+CHR$0+"*.rtf"+CHR$0+CHR$0
440 $$fp{}=LastSave$
450 fs.lStructSize% = DIM(fs{})
460 fs.hwndOwner% = @hwnd%
470 fs.lpstrFilter% = !^ff$
480 fs.lpstrInitialDir% = !^LastSave$
490 fs.lpstrFile% = fp{}
500 fs.nMaxFile% = 260
510 fs.lpstrTitle% = !^ft$
520 fs.flags% = 6
530 SYS "GetSaveFileName", fs{} TO result%
540 IF result%:ff$=$$fp{}:PROCReg_Wr(KeyRoot$+"LastSave",ff$):=ff$
550 =""
560 :
570 DEFFNReg_Rd(Key$)
580 LOCAL K%,R%,L%,T%,Item$,Value$
590 Item$=Key$:REPEAT:K%=INSTR(Item$,"\"):IF K%:Item$=MID$(Item$,K%+1)
600 UNTIL K%=0:Key$=LEFT$(Key$,LENKey$-LENItem$-1)
610 SYS "RegOpenKeyEx",&80000001,Key$,0,&20001,^K% TO R%
620 IF R%=0 THEN
630 SYS "RegQueryValueEx",K%,Item$,0,^T%,0,^L%:DIM Buf% LOCAL L%
640 SYS "RegQueryValueEx",K%,Item$,0,^T%,Buf%,^L% TO R%
650 IF R%=0:Buf%?(L%-1)=13:Value$=$Buf%
660 SYS "RegCloseKey",K%
670 ENDIF
680 =Value$
690 :
700 DEFPROCReg_Wr(Key$,Value$)
710 LOCAL K%,D%,R%,Item$
720 Item$=Key$:REPEAT:K%=INSTR(Item$,"\"):IF K%:Item$=MID$(Item$,K%+1)
730 UNTIL K%=0:Key$=LEFT$(Key$,LENKey$-LENItem$-1)
740 SYS "RegCreateKeyEx",&80000001,Key$,0,"",0,&F003F,0,^K%,^D% TO R%
750 IF R%=0 THEN
760 SYS "RegSetValueEx",K%,Item$,0,1,Value$,LENValue$+1
770 SYS "RegCloseKey",K%
780 ENDIF
790 ENDPROC