User Tools

Site Tools


saving_20previous_20load_20and_20save_20paths

Saving previous load and save paths

Please see the discussion page

It is often useful if a program remembers where a file was last loaded from or saved to so that the next time a file open or file save dialogue is used it opens on the same directory as last time. Repeated calls of SYS “GetOpenFileName” re-open on the same directory as last time (unless overridden). However, that is a system-wide setting, not a program setting, and your program may have different dialogues that should start from different directories. The following code saves the loaded or saved filename in the registry so that next time it opens on the same directory again. The Save dialogue also pre-fills the filename with the last used filename.

        DEF FNFile_Open
        ft$="Select file to load"+CHR$0
        LastLoad$ =FNReg_Rd(KeyRoot$+"LastLoad")+CHR$0
        ff$ = "All files"+CHR$0+"*.*"+CHR$0+CHR$0
        $$fp{}=LastLoad$
        fs.lStructSize% = DIM(fs{})
        fs.hwndOwner% = @hwnd%
        fs.lpstrFilter% = !^ff$
        fs.lpstrInitialDir% = !^LastLoad$
        fs.lpstrFile% = fp{}
        fs.nMaxFile% = 260
        fs.lpstrTitle% = !^ft$
        fs.flags% = 6
        SYS "GetOpenFileName", fs{} TO result%
        IF result%:ff$=$$fp{}:PROCReg_Wr(KeyRoot$+"LastLoad",ff$):=ff$
        =""
        :
        DEFFNFile_Save
        ft$="Select output file to save to"+CHR$0
        LastSave$ =FNReg_Rd(KeyRoot$+"LastSave")+CHR$0
        ff$ = "All files"+CHR$0+"*.*"+CHR$0+CHR$0
        $$fp{}=LastSave$
        fs.lStructSize% = DIM(fs{})
        fs.hwndOwner% = @hwnd%
        fs.lpstrFilter% = !^ff$
        fs.lpstrInitialDir% = !^LastSave$
        fs.lpstrFile% = fp{}
        fs.nMaxFile% = 260
        fs.lpstrTitle% = !^ft$
        fs.flags% = 6
        SYS "GetSaveFileName", fs{} TO result%
        IF result%:ff$=$$fp{}:PROCReg_Wr(KeyRoot$+"LastSave",ff$):=ff$
        =""

They are called with, for example, in$=FNFile_Open:out$=FNFile_Save. They need the usual file open dialogue structure set up with:

        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)}

The registry calls need KeyRoot$ set to your program's registry branch which must be of the form:

        KeyRoot$="Software\MySoftwareHouse\MyApplicationName\"

See Simple Registry Usage for the Reg_Rd() and Reg_Wr() routines.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
saving_20previous_20load_20and_20save_20paths.txt · Last modified: 2024/01/05 00:21 by 127.0.0.1