Save File As Dialog |
Author: |
Message: |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
O.P. Save File As Dialog
I've been searching MSDN and Google all day and can't seem to find any JScript examples of a save file as dialog, so just wondering if someone can please post some example code for me...
Thanks,
David.
|
|
08-17-2007 12:49 PM |
|
![](images/pixel.gif) |
matty
Scripting Guru
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 8328 Reputation: 109
39 / / ![Canada Flag](images/flags/ca.png)
Joined: Dec 2002
Status: Away
|
RE: Save File As Dialog
code: function SaveFileAs(sTitle, sInitialDir){
if (typeof(sTitle) === 'undefined') sTitle = '';
if (typeof(sInitialDir) === 'undefined') sInitialDir = 'C:\\';
var OpenFileName = Interop.Allocate(88);
with (OpenFileName){
WriteDWORD(0, 88); // Dodgy Microsoft, why can't you figure out the size of the struct yourself...
var s_filter = Interop.Allocate(512);
s_filter.WriteString(0, 'All Files (*.*)');
WriteDWORD(12, s_filter.DataPtr);
WriteDWORD(24, 1);
s_file = Interop.Allocate(512);
s_file.WriteString(0, '*.*');
WriteDWORD(28, s_file.DataPtr);
WriteDWORD(32, 255);
var sTmp = Interop.Allocate((254+1)*2);
WriteDWORD(36, sTmp.DataPtr);
WriteDWORD(40, 255);
var s_initdir = Interop.Allocate((sInitialDir.length+1)*2);
s_initdir.WriteString(0, sInitialDir);
WriteDWORD(44, s_initdir.DataPtr);
s_title = Interop.Allocate((sTitle.length+1)*2);
WriteDWORD(48, s_title.DataPtr);
WriteDWORD(52, 0x800000 /* OFN_ENABLESIZING */ | 0x80000 /* OFN_EXPLORER */ | 0x4 /* OFN_HIDEREADONLY */ | 0x200000 /* OFN_LONGNAMES */ | 0x800 /* OFN_PATHMUSTEXIST */ | 0x1000 /* OFN_FILEMUSTEXIST */ | 0x00000002 /* OFN_OVERWRITEPROMPT */);
}
return Interop.Call('comdlg32', 'GetSaveFileNameW', OpenFileName) !== 0 ? s_file.ReadString(0) : false;
}
This post was edited on 08-17-2007 at 01:04 PM by matty.
|
|
08-17-2007 01:02 PM |
|
![](images/pixel.gif) |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
O.P. RE: Save File As Dialog
Thanks a million man, you rock
How do I choose the file to be saved? XD
Edit: Found out myself
Would you possibly be able to edit the filter, I can't get it to work out. I need it for .jpg and .jpeg
Thanks in advance.
This post was edited on 08-17-2007 at 01:57 PM by davidpolitis.
|
|
08-17-2007 01:03 PM |
|
![](images/pixel.gif) |
Matti
Elite Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
![Avatar](http://www.gravatar.com/avatar/50cd7dac807a483ca5c470b8c8e0b2e6?s=96)
Script Developer and Helper
Posts: 1646 Reputation: 39
32 / / ![Belgium Flag](images/flags/be.png)
Joined: Apr 2004
|
RE: Save File As Dialog
Therefore, you need some changes. The s_filter can contain multiple filters and therefore you'll need to write multiple strings into the databloc. Luckily, Choli made a nice function for doing that.
I've edited Matty's code to use WriteMultiStringW and removed the OFN_FILEMUSTEXIST flag because that can't be used on a Save As dialog!
code: function SaveFileAs(sTitle, sInitialDir){
if (typeof(sTitle) === 'undefined') sTitle = '';
if (typeof(sInitialDir) === 'undefined') sInitialDir = 'C:\\';
var OpenFileName = Interop.Allocate(88);
with (OpenFileName){
WriteDWORD(0, 88); // Dodgy Microsoft, why can't you figure out the size of the struct yourself...
var filter = 'JPEG (*.jpg;*.jpeg)|*.JPEG;*.JPG|All Files (*.*)|*.*||'; // This string will be used to generate an s_filter databloc
var s_filter = Interop.Allocate(512);
WriteMultiStringW(s_filter, filter);
WriteDWORD(12, s_filter.DataPtr);
WriteDWORD(24, 1);
s_file = Interop.Allocate(512);
// s_file.WriteString(0, '*.*');
WriteDWORD(28, s_file.DataPtr);
WriteDWORD(32, 255);
var sTmp = Interop.Allocate((254+1)*2);
WriteDWORD(36, sTmp.DataPtr);
WriteDWORD(40, 255);
var s_initdir = Interop.Allocate((sInitialDir.length+1)*2);
s_initdir.WriteString(0, sInitialDir);
WriteDWORD(44, s_initdir.DataPtr);
s_title = Interop.Allocate((sTitle.length+1)*2);
WriteDWORD(48, s_title.DataPtr);
WriteDWORD(52, 0x800000 /* OFN_ENABLESIZING */ | 0x80000 /* OFN_EXPLORER */ | 0x4 /* OFN_HIDEREADONLY */ | 0x200000 /* OFN_LONGNAMES */ | 0x800 /* OFN_PATHMUSTEXIST */ | 0x1000 /* OFN_OVERWRITEPROMPT */);
}
return Interop.Call('comdlg32', 'GetSaveFileNameW', OpenFileName) !== 0 ? s_file.ReadString(0) : false;
function WriteMultiStringW (datablock, string) {
var pos = 0;
datablock.WriteString(0, string);
pos = string.indexOf("|", pos);
while (pos != -1) {
datablock.WriteWORD(2 * pos, 0);
pos = string.indexOf("|", pos + 1);
}
}
}
|
|
08-17-2007 04:06 PM |
|
![](images/pixel.gif) |
matty
Scripting Guru
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 8328 Reputation: 109
39 / / ![Canada Flag](images/flags/ca.png)
Joined: Dec 2002
Status: Away
|
RE: Save File As Dialog
Mattike you should also give props to Choli for the WriteMultiStringW function as he wrote it.
|
|
08-17-2007 04:26 PM |
|
![](images/pixel.gif) |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
O.P. RE: Save File As Dialog
Any of you have any idea why this will not work and get the current display pictures file extension?
code: function SaveFileAs(sTitle, sInitialDir)
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.GetFile(Messenger.MyDisplayPicture);
var type = file.substr(file.lastIndexOf(".") + 1);
if (typeof(sTitle) === 'undefined') sTitle = '';
if (typeof(sInitialDir) === 'undefined') sInitialDir = 'C:\\';
var OpenFileName = Interop.Allocate(88);
with (OpenFileName)
{
WriteDWORD(0, 88);
if (type == "jpg") var filter = "jpg-filter-code";
if (type == "png") var filter = "png-filter-code";
//var filter = 'JPEG (*.jpg;*.jpeg)|*.JPEG;*.JPG|';
var s_filter = Interop.Allocate(512);
WriteMultiStringW(s_filter, filter);
WriteDWORD(12, s_filter.DataPtr);
WriteDWORD(24, 1);
s_file = Interop.Allocate(512);
WriteDWORD(28, s_file.DataPtr);
WriteDWORD(32, 255);
var sTmp = Interop.Allocate((254+1)*2);
WriteDWORD(36, sTmp.DataPtr);
WriteDWORD(40, 255);
var s_initdir = Interop.Allocate((sInitialDir.length+1)*2);
s_initdir.WriteString(0, sInitialDir);
WriteDWORD(44, s_initdir.DataPtr);
s_title = Interop.Allocate((sTitle.length+1)*2);
WriteDWORD(48, s_title.DataPtr);
WriteDWORD(52, 0x800000 /* OFN_ENABLESIZING */ | 0x80000 /* OFN_EXPLORER */ | 0x4 /* OFN_HIDEREADONLY */ | 0x200000 /* OFN_LONGNAMES */ | 0x800 /* OFN_PATHMUSTEXIST */ | 0x1000 /* OFN_OVERWRITEPROMPT */);
}
file.Copy(Interop.Call('comdlg32', 'GetSaveFileNameW', OpenFileName) !== 0 ? s_file.ReadString(0) : false);
function WriteMultiStringW(datablock, string)
{
var pos = 0;
datablock.WriteString(0, string);
pos = string.indexOf("|", pos);
while (pos != -1)
{
datablock.WriteWORD(2 * pos, 0);
pos = string.indexOf("|", pos + 1);
}
}
}
Sorry about the formatting, if you want go here: http://pastebin.com/d7794d483
This post was edited on 08-17-2007 at 10:16 PM by davidpolitis.
|
|
08-17-2007 10:15 PM |
|
![](images/pixel.gif) |
Spunky
Former Super Mod
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
![Avatar](http://i39.tinypic.com/345jujo.png)
Posts: 3656 Reputation: 61
36 / / ![United Kingdom Flag](images/flags/gb.png)
Joined: Aug 2006
|
RE: Save File As Dialog
quote: Originally posted by davidpolitis
Any of you have any idea why this will not work and get the current display pictures file extension?
Isn't it ALWAYS converted to png?
<Eljay> "Problems encountered: shit blew up" ![:zippy:](images/smilies/zippy.gif)
|
|
08-18-2007 08:07 AM |
|
![](images/pixel.gif) |
davidpolitis
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
Posts: 371 Reputation: 16
Joined: Aug 2006
|
O.P. RE: Save File As Dialog
No, well... I tested and MP!L returns the file as being the same file format as the original image file.
|
|
08-18-2007 12:18 PM |
|
![](images/pixel.gif) |
MeEtc
Patchou's look-alike
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
![Avatar](http://meetcweb.com/up/v.png)
In the Shadow Gallery once again
Posts: 2191 Reputation: 60
39 / / ![Canada Flag](images/flags/ca.png)
Joined: Nov 2004
Status: Away
|
RE: Save File As Dialog
The file is definitly NOT always png. I had problems trying to get the DP showing in my sig image using CreateImageFromPNG. Well, that function fails if your file is a jpg. took me forever to figure out why
![[Image: sharing.png]](http://www.meetcweb.com/files/sharing.png)
I cannot hear you. There is a banana in my ear.
|
|
08-18-2007 12:33 PM |
|
![](images/pixel.gif) |
TheSteve
Full Member
![*](images/star.gif) ![*](images/star.gif) ![*](images/star.gif)
![Avatar](avatar.php?uid=49468-8325)
The Man from Japan
Posts: 179 Reputation: 23
40 / / ![Japan Flag](images/flags/jp.png)
Joined: Aug 2005
|
RE: RE: Save File As Dialog
quote: Originally posted by matty
code: // Dodgy Microsoft, why can't you figure out the size of the struct yourself...
There are different versions of the structure. The size determines which you are using. For example, if the symbol _MAC is defined, the structure will grow by 8 bytes. If you're using windows 2000 or greater it will grow another 12 bytes.
|
|
08-20-2007 12:22 AM |
|
![](images/pixel.gif) |
Pages: (2):
« First
[ 1 ]
2
»
Last »
|
|
|