June 19, 2019, 01:43:18 pm

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


Save As dialog

Started by Brian, May 23, 2019, 10:08:04 am

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Brian

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


fasecero

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

Code Select
$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


Brian

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

Andy

Yes,

That's a good question Brian!

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

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.