IonicWind Software

IWBasic => General Questions => Topic started by: Brian on May 23, 2019, 10:08:04 AM

Title: Save As dialog
Post by: Brian on May 23, 2019, 10:08:04 AM
Hello,

Is it possible, when using the Save As file dialog, to have a filename inserted into the filename area?
My program opens a text file. When I use the Filerequest control, I want the last-opened file's name to be inserted automatically
Any ideas?

Brian

Title: Re: Save As dialog
Post by: fasecero on May 24, 2019, 11:42:41 AM
It seems that FILEREQUEST does not have this feature but it is doable. You can use SaveFileDialog function below. Choose a file twice to check if works ok :)

$INCLUDE "windowssdk.inc"

string fullPath = "" ' path to our filename

CONST STATIC_2 = 2
CONST BUTTON_1 = 1
WINDOW w1
OPENWINDOW w1,0,0,670,300,@MINBOX|@MAXBOX|@SIZE,NULL,"Simple Window",&w1_handler
CONTROL w1,@BUTTON,"Show Dialog",69,100,154,62,0x50000000,BUTTON_1
CONTROL w1,@STATIC,"Select a file...",233,124,346,26,0x5000010B,STATIC_2

' main loop
WAITUNTIL w1 = 0
END
 
' window procedure
SUB w1_handler(), INT
SELECT @MESSAGE
CASE @IDCREATE
CENTERWINDOW w1
OleInitialize(0)

CASE @IDCLOSEWINDOW
OleUninitialize()
CLOSEWINDOW w1

CASE @IDCONTROL
SELECT @CONTROLID
CASE BUTTON_1
IF @NOTIFYCODE = 0
/*button clicked*/
fullPath = SaveFileDialog("Save filename",w1.hwnd, "Text Files *.txt|*.txt|All Files (*.*)|*.*||", "txt", "", fullPath)

IF LEN(fullPath) THEN
SETCONTROLTEXT w1, STATIC_2, fullPath
ELSE
SETCONTROLTEXT w1, STATIC_2, "Select a file...                                                      "
ENDIF
ENDIF
ENDSELECT
ENDSELECT

RETURN 0
ENDSUB

SUB SaveFileDialog(string title, int parent, string filter, string ext, string initdir, string filename), string
OPENFILENAME ofn
STRING filtercopy = ""
string buffer = filename

ZeroMemory(filtercopy, LEN(filtercopy))
    ZeroMemory(&ofn, LEN(ofn))
    ofn.lStructSize = LEN(ofn)
    ofn.hwndOwner = parent

INT x
FOR x = 0 TO 255
filtercopy[x] = 0
NEXT x

FOR x = 0 TO LEN(filter) - 1
IF filter[x] = "|" THEN
filtercopy[x] = 0
ELSE
filtercopy[x] = filter[x]
ENDIF
NEXT x

ofn.lpstrFilter = filtercopy
    ofn.lpstrFile = buffer
    ofn.nMaxFile = 255
ofn.lpstrInitialDir = initdir
    ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT
    ofn.lpstrDefExt = ext
ofn.lpstrTitle = title

    IF GetSaveFileName(&ofn) THEN RETURN ofn.lpstrFile
RETURN ""
ENDSUB

Title: Re: Save As dialog
Post by: Brian on May 24, 2019, 11:59:58 AM
Fasecero,

That's neat! And I see that if you load the variable "filename" with an initial name of your own, then that is inserted into the file name space in the dialog. Thank you so much. I was beginning to realise that it would be a roll-your-own job

Brian
Title: Re: Save As dialog
Post by: Andy on May 25, 2019, 05:23:02 AM
Yes,

That's a good question Brian!

It would be nice to amend the code to do that.

Andy.