|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Using GetSaveFileName API with VB6"sDefFileExt is a pointer to a buffer that contains the default extension. GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension." Observe that: "if the user fails to type an extension" proviso. Problem: I am using sDefFileExt with GetSaveFileName, but the extension in sDefFileExt is being appended EVEN IF I type in a different extension. I've got sDefFileExt = "lay" & vbNullChar & vbNullChar (I am NOT including the leading dot in sDefFileExt, as per the notes.) For example, if sDefFileExt = "lay" and I type in "dummy.xyz" in the GetSaveFileName dialog then the dialog returns "dummy.xyz.lay" What I'm trying to achieve is: - If filename is typed in with an extension and the extension matches sDefFileExt, e.g. xyz123.lay, then if file exists, then warn to overwrite, else return xyz123.lay - If NO extension typed, append sDefFileExt. If file exists, then warn to overwrite, else return e.g. abc456.lay - if a filename with a DIFFERENT extension is typed, e.g. fgh654.xyz, if file exists, then warn to overwrite, else return fgh654.xyz What is *actually* returned in the last example above is gfh654.xyz.lay, that is, despite my typing an extension that is different from the one given in sDefFileExt, Windows is appending sDefFileExt to my extension! ****************************************************************************** This behaviour by Windows makes no sense and is contrary to the explanatory notes for GetSaveFileName ****************************************************************************** Is there a way of doing what I want with the dialog flags? Or do I have to code around it? Or am I completely missing something? NB: I am using OFN_OVERWRITEPROMPT. This PC is running Windows 98SE and VB6/SP6. Thanks! MM MM wrote:
> What is *actually* returned in the last example above is Yeah, that's the way Windows works. Try opening a new document in Word, and Save as > gfh654.xyz.lay, that is, despite my typing an extension that is > different from the one given in sDefFileExt, Windows is appending > sDefFileExt to my extension! "Doc1.xyz" -- see what you get. :-( > ****************************************************************************** Maybe it'll help to realize it was written when *every* file was an 8.3 critter, and > This behaviour by Windows makes no sense and is contrary to the > explanatory notes for GetSaveFileName > ****************************************************************************** that dots weren't valid filename characters? > Is there a way of doing what I want with the dialog flags? Or do I I think you have to code around it. And who's to say, really, that the user doesn't > have to code around it? Or am I completely missing something? want a file with two dots in it?
Show quote
Hide quote
On Wed, 25 Mar 2009 18:10:03 -0700, "Karl E. Peterson" <k***@mvps.org> Fine, but why do the docs say the def extension will be appended IFwrote: >MM wrote: >> What is *actually* returned in the last example above is >> gfh654.xyz.lay, that is, despite my typing an extension that is >> different from the one given in sDefFileExt, Windows is appending >> sDefFileExt to my extension! > >Yeah, that's the way Windows works. Try opening a new document in Word, and Save as >"Doc1.xyz" -- see what you get. :-( > >> ****************************************************************************** >> This behaviour by Windows makes no sense and is contrary to the >> explanatory notes for GetSaveFileName >> ****************************************************************************** > >Maybe it'll help to realize it was written when *every* file was an 8.3 critter, and >that dots weren't valid filename characters? > >> Is there a way of doing what I want with the dialog flags? Or do I >> have to code around it? Or am I completely missing something? > >I think you have to code around it. And who's to say, really, that the user doesn't >want a file with two dots in it? the user didn't type one? Are the docs wrong or is this a bug? MM
Show quote
Hide quote
"MM" <kylix***@yahoo.co.uk> wrote in message I consider this proper operation. Normally, to save any document, you select news:60fms49t2sc8dko1livpvlmokmd8dodbqc@4ax.com... > On Wed, 25 Mar 2009 18:10:03 -0700, "Karl E. Peterson" <k***@mvps.org> > wrote: > >>MM wrote: >>> What is *actually* returned in the last example above is >>> gfh654.xyz.lay, that is, despite my typing an extension that is >>> different from the one given in sDefFileExt, Windows is appending >>> sDefFileExt to my extension! >> >>Yeah, that's the way Windows works. Try opening a new document in Word, >>and Save as >>"Doc1.xyz" -- see what you get. :-( >> >>> ****************************************************************************** >>> This behaviour by Windows makes no sense and is contrary to the >>> explanatory notes for GetSaveFileName >>> ****************************************************************************** >> >>Maybe it'll help to realize it was written when *every* file was an 8.3 >>critter, and >>that dots weren't valid filename characters? >> >>> Is there a way of doing what I want with the dialog flags? Or do I >>> have to code around it? Or am I completely missing something? >> >>I think you have to code around it. And who's to say, really, that the >>user doesn't >>want a file with two dots in it? > > Fine, but why do the docs say the def extension will be appended IF > the user didn't type one? Are the docs wrong or is this a bug? > a FILE TYPE, which usually defines an extension. Windows, then, is saying that if you do not add the proper extension, for that file type, it will add it for you. Any other extension can easily, and is, interpreted as part of the file name. Like when saving an Excel XLS spreadsheet: Save as MyFile.xls > MyFile.xls Save as MyFile > MyFile.xls Save as My.Document > My.Document.xls Save as My.Doc > My.Doc.xls I consider these all proper, and expected, operation. If you don't use the proper extension for the file type being saved, the program (or maybe it's Windows, don't know) adds the standard extension for you. -- Regards, Rick Raisley heavymetal-A-T-bellsouth-D-O-T-net On Thu, 26 Mar 2009 07:59:30 -0400, "Rick Raisley"
<heavymetal-A-T-bellsouth-D-O-Tnet> wrote: Show quoteHide quote >"MM" <kylix***@yahoo.co.uk> wrote in message Fine, but that's not what the docs say! From the horse's mouth (MSDN):>news:60fms49t2sc8dko1livpvlmokmd8dodbqc@4ax.com... >> On Wed, 25 Mar 2009 18:10:03 -0700, "Karl E. Peterson" <k***@mvps.org> >> wrote: >> >>>MM wrote: >>>> What is *actually* returned in the last example above is >>>> gfh654.xyz.lay, that is, despite my typing an extension that is >>>> different from the one given in sDefFileExt, Windows is appending >>>> sDefFileExt to my extension! >>> >>>Yeah, that's the way Windows works. Try opening a new document in Word, >>>and Save as >>>"Doc1.xyz" -- see what you get. :-( >>> >>>> ****************************************************************************** >>>> This behaviour by Windows makes no sense and is contrary to the >>>> explanatory notes for GetSaveFileName >>>> ****************************************************************************** >>> >>>Maybe it'll help to realize it was written when *every* file was an 8.3 >>>critter, and >>>that dots weren't valid filename characters? >>> >>>> Is there a way of doing what I want with the dialog flags? Or do I >>>> have to code around it? Or am I completely missing something? >>> >>>I think you have to code around it. And who's to say, really, that the >>>user doesn't >>>want a file with two dots in it? >> >> Fine, but why do the docs say the def extension will be appended IF >> the user didn't type one? Are the docs wrong or is this a bug? >> > >I consider this proper operation. Normally, to save any document, you select >a FILE TYPE, which usually defines an extension. Windows, then, is saying >that if you do not add the proper extension, for that file type, it will add >it for you. Any other extension can easily, and is, interpreted as part of >the file name. Like when saving an Excel XLS spreadsheet: > >Save as MyFile.xls > MyFile.xls >Save as MyFile > MyFile.xls >Save as My.Document > My.Document.xls >Save as My.Doc > My.Doc.xls > >I consider these all proper, and expected, operation. > >If you don't use the proper extension for the file type being saved, the >program (or maybe it's Windows, don't know) adds the standard extension for >you. "GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension." If I type MyFile.xyz I don't expect Windows to add the def extension, e.g. MyFile.xyz.lay, but it is. This is plain wrong. The OFN member is, after all, called s....DEF.....FileExt!! That is, it's intended as the DEFault for when nothing was specified. MM MM wrote:
Show quoteHide quote >>> What is *actually* returned in the last example above is I thought I already answered that? I'm almost sure it's because the docs were >>> gfh654.xyz.lay, that is, despite my typing an extension that is >>> different from the one given in sDefFileExt, Windows is appending >>> sDefFileExt to my extension! >> >>Yeah, that's the way Windows works. Try opening a new document in Word, and Save >>as "Doc1.xyz" -- see what you get. :-( >> >>> ****************************************************************************** >>> This behaviour by Windows makes no sense and is contrary to the >>> explanatory notes for GetSaveFileName >>> ****************************************************************************** >> >>Maybe it'll help to realize it was written when *every* file was an 8.3 critter, >>and that dots weren't valid filename characters? >> >>> Is there a way of doing what I want with the dialog flags? Or do I >>> have to code around it? Or am I completely missing something? >> >>I think you have to code around it. And who's to say, really, that the user >>doesn't want a file with two dots in it? > > Fine, but why do the docs say the def extension will be appended IF > the user didn't type one? Are the docs wrong or is this a bug? written in the Win16 days, and Microsoft is really lame about updating that level of detail. You got an old copy of Appleman lying around? I could probably dig out the exact text, by loading up an old Win16 SDK, but I imagine you could too. As I said, "back in the day" files only had *one* dot in them. Perhaps it actually worked as you're currently interpreting it, back then? I don't recall. It's a plausible explanation for the confusion, though.
Show quote
Hide quote
On Thu, 26 Mar 2009 13:05:58 -0700, "Karl E. Peterson" <k***@mvps.org> Appleman doesn't cover GetSaveFileName. I've just checked the .hlpwrote: >MM wrote: >>>> What is *actually* returned in the last example above is >>>> gfh654.xyz.lay, that is, despite my typing an extension that is >>>> different from the one given in sDefFileExt, Windows is appending >>>> sDefFileExt to my extension! >>> >>>Yeah, that's the way Windows works. Try opening a new document in Word, and Save >>>as "Doc1.xyz" -- see what you get. :-( >>> >>>> ****************************************************************************** >>>> This behaviour by Windows makes no sense and is contrary to the >>>> explanatory notes for GetSaveFileName >>>> ****************************************************************************** >>> >>>Maybe it'll help to realize it was written when *every* file was an 8.3 critter, >>>and that dots weren't valid filename characters? >>> >>>> Is there a way of doing what I want with the dialog flags? Or do I >>>> have to code around it? Or am I completely missing something? >>> >>>I think you have to code around it. And who's to say, really, that the user >>>doesn't want a file with two dots in it? >> >> Fine, but why do the docs say the def extension will be appended IF >> the user didn't type one? Are the docs wrong or is this a bug? > >I thought I already answered that? I'm almost sure it's because the docs were >written in the Win16 days, and Microsoft is really lame about updating that level of >detail. You got an old copy of Appleman lying around? file ("Visual Basic Programmer's Guide to the Win32 API") The explanation for OPENFILENAME Structure on MSDN (http://tinyurl.com/636mv7) should be fairly up to date, since it mentions NT, 2000 and XP, and it still says "GetOpenFileName and GetSaveFileName append this extension to the file name if the user fails to type an extension." > I could probably dig out the I've found a promising-looking file in my CD-ROM archive named>exact text, by loading up an old Win16 SDK, but I imagine you could too. psdk-x86.exe, dated March 2000, so I'll take a look at that. >As I said, "back in the day" files only had *one* dot in them. Perhaps it actually I wouldn't get too hooked up on multiple dots! Wanting TWO dots is>worked as you're currently interpreting it, back then? I don't recall. It's a >plausible explanation for the confusion, though. perverse. Expecting Windows to honour its pledge to append the extension IF the user didn't provide one is not. MM MM wrote:
>>I thought I already answered that? I'm almost sure it's because the docs were Oh well. You want to make it worth it for me to find an old Win16 SDK, so I can >>written in the Win16 days, and Microsoft is really lame about updating that level >>of detail. You got an old copy of Appleman lying around? > > Appleman doesn't cover GetSaveFileName. I've just checked the .hlp > file ("Visual Basic Programmer's Guide to the Win32 API") show you the wording hasn't changed (much)? > The explanation for OPENFILENAME Structure on MSDN Operative word there being "should" huh? <shrug>> (http://tinyurl.com/636mv7) should be fairly up to date, > since it Look, you can argue all you want, but that doesn't change the *fact* that Microsoft > mentions NT, 2000 and XP, and it still says "GetOpenFileName and > GetSaveFileName append this extension to the file name if the user > fails to type an extension." rarely goes over their docs at this level of detail. >>As I said, "back in the day" files only had *one* dot in them. Perhaps it Heh, I use that style routinely, now. For example, if you need to email someone an >>actually >>worked as you're currently interpreting it, back then? I don't recall. It's a >>plausible explanation for the confusion, though. > > I wouldn't get too hooked up on multiple dots! Wanting TWO dots is > perverse. EXE or REG file, you can do: whatever.exe.xyz export.reg.txt viral.vbs.txt And so on. <g> > Expecting Windows to honour its pledge to append the I'd say your issue is that the definition of "extension" has changed over the years, > extension IF the user didn't provide one is not. but you haven't. If you want the option not to append the default
then include an option for All files *.*. Generally the way it's done is to include a dropdown option for all file types that the program saves in, plus the All Files option. On Wed, 25 Mar 2009 23:43:58 -0500, "mayayana" <mayayaX***@rcXXn.com> Nope. Didn't work. I just whacked in All files *.* and did Save Aswrote: > If you want the option not to append the default >then include an option for All files *.*. Generally >the way it's done is to include a dropdown option for >all file types that the program saves in, plus the All >Files option. dummy.qwe It has saved the file as dummy.qwe.lay Here's my revised call to wrapper around GetSaveFileName: s = ShowSaveAsDialog("Save Layout File", "Layout Files (*.lay)" & Chr$(0) & "*.lay" & Chr$(0) & "All Files (*.*)" & Chr$(0) & "*.*" & Chr$(0), AppPath) Flags: OFName.flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT MM Interesting. I just did a little test and found that
it worked the way you describe. I agree that it doesn't make much sense. There's no point in having an All Files option if it's going to save with a default extension. Worse, if your def. extension is more than 3 characters it will be clipped. According to the docs it's supposed to work that way. You just have to do it yourself if you want it to work properly. (Note: You're supposed to have a double null at the end, but it doesn't sound like that's stopping your code from working.) I haven't dealt with this for awhile, but looking at my own code where I've provided several save options plus an "All files" option, I see that I apparently once knew about this aberration. :) What I did was to use: .lpstrDefExt = vbNullString in the OPENFILENAME structure. That prevents any extension being added. I then deal with the result in the save function by checking ..NFilterIndex to find out which filter was selected. So it would be something like: If OFN.NFilterIndex = 1 then '-- add ".lay" if it wasn't entered by the person saving the file. End if '-- If index is 2 then it's all files, so save as entered. Show quoteHide quote > Nope. Didn't work. I just whacked in All files *.* and did Save As > dummy.qwe > > It has saved the file as dummy.qwe.lay > > Here's my revised call to wrapper around GetSaveFileName: > > s = ShowSaveAsDialog("Save Layout File", "Layout Files (*.lay)" & > Chr$(0) & "*.lay" & Chr$(0) & "All Files (*.*)" & Chr$(0) & "*.*" & > Chr$(0), AppPath) > > Flags: OFName.flags = OFN_HIDEREADONLY Or OFN_OVERWRITEPROMPT > > MM On Thu, 26 Mar 2009 10:37:11 -0500, "mayayana" <mayayaX***@rcXXn.com> I'm about to surf to http://ccrp.mvps.org/ to see whether they didwrote: > Interesting. I just did a little test and found that >it worked the way you describe. I agree that it doesn't >make much sense. There's no point in having an All >Files option if it's going to save with a default extension. >Worse, if your def. extension is more than 3 characters >it will be clipped. According to the docs it's supposed to >work that way. You just have to do it yourself if you want >it to work properly. anything. > Yeah, I've tried it with and without the null(s), but it doesn't seem> (Note: You're supposed to have a double null at the end, >but it doesn't sound like that's stopping your code from >working.) to make any difference. MM "MM" <kylix***@yahoo.co.uk> wrote... My understanding is that if the file name contains a registered file > On Wed, 25 Mar 2009, "mayayana" <mayayaX***@rcXXn.com> wrote: > >> If you want the option not to append the default >>then include an option for All files *.*. Generally >>the way it's done is to include a dropdown option for >>all file types that the program saves in, plus the All >>Files option. > > Nope. Didn't work. I just whacked in All files *.* and did Save As > dummy.qwe > > It has saved the file as dummy.qwe.lay extension then the DefaultExe is not added. If there is not a recognized extension, then any dot is assumed to be a part of the file name and the DefaultExe is added. David David Youngblood wrote:
> My understanding is that if the file name contains a registered file Open Word and save the default new document as Doc1.txt - see what happens.> extension then the DefaultExe is not added. If there is not a recognized > extension, then any dot is assumed to be a part of the file name and the > DefaultExe is added. "Karl E. Peterson" <k***@mvps.org> wrote in message That annoying paperclip opened up, pointed at me and then fell to the news:%23ftvbimrJHA.4460@TK2MSFTNGP06.phx.gbl... | | Open Word and save the default new document as Doc1.txt - see what happens. | -- virtual floor, laughting its metal ass off. Odd. "Karl E. Peterson" <k***@mvps.org> wrote in message... Yes, but Word does not use the common dialog, so rules can differ. Try > David Youngblood wrote: >> My understanding is that if the file name contains a registered file >> extension then the DefaultExe is not added. If there is not a recognized >> extension, then any dot is assumed to be a part of the file name and the >> DefaultExe is added. > > Open Word and save the default new document as Doc1.txt - see what > happens. selecting Plain Text (*.txt) file type and trying that test again with various file extensions. Word will allow you to save text as any registered file type (all that I tested anyway), only if the extension is not recognized will the txt extension be added. I'm using Word 2002, other versions may work differently. David David Youngblood wrote:
Show quoteHide quote > "Karl E. Peterson" <k***@mvps.org> wrote in message... D'oh! Yep, you're right. "Nevermind..." :-)>> David Youngblood wrote: >>> My understanding is that if the file name contains a registered file >>> extension then the DefaultExe is not added. If there is not a recognized >>> extension, then any dot is assumed to be a part of the file name and the >>> DefaultExe is added. >> >> Open Word and save the default new document as Doc1.txt - see what >> happens. > > Yes, but Word does not use the common dialog, so rules can differ. Try > selecting Plain Text (*.txt) file type and trying that test again with > various file extensions. Word will allow you to save text as any registered > file type (all that I tested anyway), only if the extension is not > recognized will the txt extension be added. I'm using Word 2002, other > versions may work differently.
Show quote
Hide quote
"David Youngblood" <d**@flash.net> wrote in message Yep that's what I see here.news:u%237yvXmrJHA.1236@TK2MSFTNGP02.phx.gbl... > "MM" <kylix***@yahoo.co.uk> wrote... >> On Wed, 25 Mar 2009, "mayayana" <mayayaX***@rcXXn.com> wrote: >> >>> If you want the option not to append the default >>>then include an option for All files *.*. Generally >>>the way it's done is to include a dropdown option for >>>all file types that the program saves in, plus the All >>>Files option. >> >> Nope. Didn't work. I just whacked in All files *.* and did Save As >> dummy.qwe >> >> It has saved the file as dummy.qwe.lay > > My understanding is that if the file name contains a registered file > extension then the DefaultExe is not added. If there is not a recognized > extension, then any dot is assumed to be a part of the file name and the > DefaultExe is added. > Bill McCarthy wrote:
>> My understanding is that if the file name contains a registered file Open Word and save the default new document as Doc1.txt - see what happens.>> extension then the DefaultExe is not added. If there is not a recognized >> extension, then any dot is assumed to be a part of the file name and the >> DefaultExe is added. > > Yep that's what I see here.
Other interesting topics
Beep Again
URLDownloadToFile API failing due to disclaimer page IsVista SQL Server Compact Edition with VB6 VB6 IDE Find doesn't Subscript out of range VB 6 on loading a form OT: Can cause VB6 an error of this kind? Simple timer uses more and more memory ordered list - sorta The application failed to initialize properly |
|||||||||||||||||||||||