April 25, 2024, 06:05:21 PM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Default Filename for Filerequest?

Started by RG, August 19, 2011, 10:33:00 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

RG

After an 18 month hiatus, I'm back to programming with ebasic, putting in the final touches on a program. One thing I can't figure out is how to make a default filename appear when filerequest is called. I vaguely remember this coming up before, but after searching and browsing the forum I can't spot the answer. What I'm looking to do is similar to what MS Word would do: if I have previously opened a document, when I use "Save As", the filename that was originally used to open the document appears as a default in the filename box; the standard fiilerequest dialog in ebasic shows a blank filename box. The previous filename is known to the dialog, as there is a drop down box that shows all the recently opened files (but because it shows the full path, all I can see is the directory path and can't scroll over to the actual filename). The help files doesn't show any option to display the filename. Any thoughts?

Thanks for any help
Rich

LarryMc

This should get you crackin'

DEF win:WINDOW
OPENWINDOW win,0,0,640,400,@SIZE|@MINBOX|@MAXBOX,0,"Skeleton",&mainwindow
beginmenu win
   menutitle "&File"
      menuitem "Save As",0,3
      menuitem "Quit",0,4
endmenu

run = 1
WAITUNTIL run=0
CLOSEWINDOW win
END

SUB mainwindow(),int
SELECT @CLASS
   CASE @IDCLOSEWINDOW
      run = 0
   CASE @IDMENUPICK
      SELECT @MENUNUM
         CASE 3
            'save
DEF filename[260] as iSTRING
filename = "c:\\__iwbdev\\initial.txt"
filename=CustomSaveAs("Save As...",NULL,"Text Files (*.txt)|*.txt||","txt",filename)
messagebox win,filename, "Saved filepath"
         CASE 4
            'quit the program
            run = 0
      ENDSELECT
   CASE @IDCREATE
      CENTERWINDOW win
ENDSELECT
RETURN 0
ENDSUB



'============================================================================
SETID "OFN_EXPLORER" , 0x80000
SETID "OFN_HIDEREADONLY" , 0x4
SETID "OFN_OVERWRITEPROMPT" , 0x2

TYPE OPENFILENAME
   DEF lStructSize:INT
   DEF hwndOwner:INT
   DEF hInstance:INT
   DEF lpstrFilter:POINTER
   DEF lpstrCustomFilter:POINTER
   DEF nMaxCustFilter:INT
   DEF nFilterIndex:INT
   DEF lpstrFile:POINTER
   DEF nMaxFile:INT
   DEF lpstrFileTitle:POINTER
   DEF nMaxFileTitle:INT
   DEF lpstrInitialDir:POINTER
   DEF lpstrTitle:POINTER
   DEF flags:INT
   DEF nFileOffset:WORD
   DEF nFileExtension:WORD
   DEF lpstrDefExt:POINTER
   DEF lCustData:INT
   DEF lpfnHook:INT
   DEF lpTemplateName:POINTER
ENDTYPE
TYPE OPENFILENAMEEX
   DEF ofn as OPENFILENAME
   DEF pvReserved as POINTER
   DEF dwReserved as UINT
   DEF FlagsEx as UINT
ENDTYPE
DECLARE IMPORT,GetSaveFileNameA(ofx as OPENFILENAMEEX),INT
DECLARE IMPORT,ZeroMemory ALIAS RtlZeroMemory(pvoid as POINTER,length as INT),INT
DECLARE IMPORT,GetVersion(),UINT


SUB CustomSaveAs(title as STRING,parent as POINTER,OPT filter as STRING,OPT ext as STRING,OPT filename as STRING),STRING
   DEF ofn as OPENFILENAMEEX
   DEF pTest as POINTER
   DEF filtercopy[256]as CHAR
   DEF strReturn[260] as ISTRING
   ZeroMemory(ofn,LEN(OPENFILENAMEEX))
   ZeroMemory(strReturn,260)
   filtercopy[0] = 0
   IF (GetVersion() & 0x000000FF) >= 5
      ofn.ofn.lStructSize = LEN(OPENFILENAMEEX)
   ELSE
      ofn.ofn.lStructSize = LEN(OPENFILENAME)
   ENDIF
   ofn.ofn.lpstrTitle = title
   IF parent <> 0 THEN ofn.ofn.hwndOwner = #<WINDOW>parent.hwnd
   pTest = filter
   IF pTest <> 0
      x = 0
      DO
         IF filter[x] = ASC("|") THEN filtercopy[x] = 0 ELSE filtercopy[x] = filter[x]
         x=x+1
         IF x > 253 THEN filter[x] = 0
      UNTIL filter[x] = 0
      filtercopy[x] = 0
      filtercopy[x+1] = 0
   ENDIF
   ofn.ofn.lpstrFilter = filtercopy
   ofn.ofn.lpstrDefExt = ext
   pTest = filename
   IF pTest <> NULL
      strReturn = filename
   ENDIF
   ofn.ofn.lpstrFile = strReturn     
   ofn.ofn.nMaxFile = 260
   ofn.ofn.flags = @OFN_HIDEREADONLY | @OFN_EXPLORER | @OFN_OVERWRITEPROMPT
   nReturn = GetSaveFileNameA(ofn)
   IF nReturn = 0 THEN strReturn = ""
RETURN strReturn
ENDSUB


LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

RG

Larry,

That was fast! Works like a charm. I'll have to study it to better understand how it works but I was able to incorporate it into my program with ease. Was this something you already had or did you just know where to look?

Thanks, Rich

LarryMc

I found it in some of the old stuff I've got.  I didn't write the original but did clean it up some.
It's very similiar to the source code of the FILEREQUEST command.

LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

billhsln

QuoteI found it in some of the old stuff I've got.

That statement makes me wonder if you have other gems of code that would be useful or interesting.

Bill
When all else fails, get a bigger hammer.

LarryMc

who knows.  when itcomes to code I tend to be pack rat.

my biggest problem is my memory.
:o
LarryMc
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library