What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [HELP] Browsing to save a file

[HELP] Browsing to save a file
Author: Message:
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. [HELP] Browsing to save a file
Hi,

I want to save a file, using Windows' "Save File"-dialog and return the selected path, filename and extension, but I have no idea how to.. The MSDN descriptions don't make any sense to me..

Could anybody please help me?

Thanks in advance..

This post was edited on 05-20-2008 at 03:04 PM by SmokingCookie.
05-20-2008 02:56 PM
Profile PM Find Quote Report
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: [HELP] Browsing to save a file
Have a look at matty's reply to Browse For File.

You'll probably need to modify some things, as I don't think you want the dialog to open at script start-up for example, but I think you'll be able to figure that out. Also, because that code was written for an Open File dialog, you'll have to make some modifications to get a Save File dialog, for example you'll have to call GetSaveFileName instead of GetOpenFileName. You'll also have to change the flags in the structure, as some flags only work with Open File dialogs and others are interesting to use for a Save File dialog. :)

Experiment with it. It's the only way to actually learn how to do it. ;)
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
05-20-2008 03:48 PM
Profile E-Mail PM Web Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. RE: [HELP] Browsing to save a file
Well, thank you :D

I have taken a quick look and don't really understand it (because it's a quick look).. I'll take a good hard look at it later this evening ;)

Again thank you for the quick reply and the information :D

EDIT::

I have inserted the code and changed everything with "Open" to "Save", but it won't work.. It returns a 0 as path...

This post was edited on 05-20-2008 at 04:39 PM by SmokingCookie.
05-20-2008 04:04 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [HELP] Browsing to save a file
Do some research just editing code isn't going to help you learn.

Post your code so we can give you an idea where you went wrong.
05-20-2008 07:41 PM
Profile E-Mail PM Find Quote Report
SmokingCookie
Senior Member
****

Avatar

Posts: 815
Reputation: 15
30 / Male / Flag
Joined: Jul 2007
O.P. RE: [HELP] Browsing to save a file
I don't understand those flags etc., but here's the code anyway:

code:
function BrowseFile(filter,title,file) { // these ARE specified
    var SaveFileName = Interop.Allocate(88);
    var filter;
    var s_filter;
    var file;
    var s_file;
    var s_title;
    var ret;
    var tdata;
    with(SaveFileName) {
        WriteDWORD(0,Size); // lStructSize
        WriteDWORD(4,0); // hwndOwner
        WriteDWORD(8,0); // hInstance
        filter;
        s_filter = Interop.Allocate(2 * (filter.length + 1));
        WriteMultiStringW(s_filter, filter);
        WriteDWORD(12,s_filter.DataPtr); // lpstrFilter
        WriteDWORD(16,0); // lpstrCustomFilter
        WriteDWORD(20,0); // nMaxCustomFilter
        WriteDWORD(24,1); // nFilterIndex
        file + Space(256);
        s_file = Interop.Allocate(2 * (file.length + 1));
        s_file.WriteString(0,file);
        WriteDWORD(28,s_file.DataPtr); // lpstrFile
        WriteDWORD(32,file.length); // nMaxFile
        WriteDWORD(36,0); // lpstrFileTitle
        WriteDWORD(40,0); // nMaxFileTitle
        WriteDWORD(44,0); // lpstrInitialDir
        title;
        s_title = Interop.Allocate(2 * (title.length + 1));
        s_title.WriteString(0,title);
        WriteDWORD(48,s_title.DataPtr); // lpstrTitle
        WriteDWORD(52,OFN_ENABLESIZING | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_PATHMUSTEXIST/* | OFN_FILEMUSTEXIST*/); // flags
        WriteWORD(56,0); // nFileOffset
        WriteWORD(58,0); // nFileExtension
        WriteDWORD(60,0); // lpstrDefExt
        WriteDWORD(64,0); // lCustData
        WriteDWORD(68,0); // lpfnHook
        WriteDWORD(72,0); // lpTemplateName
        WriteDWORD(76,0); // pvReserved
        WriteDWORD(80,0); // dwReserved
        WriteDWORD(84,0); // FlagsEx
    }
    with(SaveFileName) {
        Ret = Interop.Call("comdlg32.dll","GetSaveFileNameW",SaveFileName);
        if(ret == 0) {
            return "__none";
        } else {
            return Ret;
        }
    }
}

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);
    }
}

function Space(number) {
    var i;
    var s = "";
    for(i = 0; i < number; i++) {
        s += " ";
    }
    return s;
}

05-20-2008 07:44 PM
Profile PM Find Quote Report
roflmao456
Skinning Contest Winner
****

Avatar

Posts: 955
Reputation: 24
29 / Male / Flag
Joined: Nov 2006
Status: Away
RE: [HELP] Browsing to save a file
maybe this could work (xp only?):
code:
function SaveFile(){
var SFD = new ActiveXObject("SAFRCFileDlg.FileSave");
SFD.FileName = "*.*";
SFD.FileType = "*.*";
if(SFD.OpenFileSaveDlg()){
return SFD.FileName;
}
return false;
}


run this JS script in wscript.exe. since it uses the jscript scripting engine, it works ;)

This post was edited on 05-20-2008 at 08:03 PM by roflmao456.
[quote]
Ultimatess6
: What a noob mod
05-20-2008 07:52 PM
Profile PM Web Find Quote Report
Spunky
Former Super Mod
*****

Avatar

Posts: 3658
Reputation: 61
35 / Male / Flag
Joined: Aug 2006
RE: [HELP] Browsing to save a file
quote:
Originally posted by roflmao456
maybe this could work (xp only?):
code:
function SaveFile(){
var SFD = new ActiveXObject("SAFRCFileDlg.FileSave");
SFD.FileName = "*.*";
SFD.FileType = "*.*";
if(SFD.OpenFileSaveDlg()){
return SFD.FileName;
}
return false;
}


run this JS script in wscript.exe. since it uses the jscript scripting engine, it works ;)

Doesn't work on vista in WScript here
<Eljay> "Problems encountered: shit blew up" :zippy:
05-20-2008 09:43 PM
Profile PM Find Quote Report
matty
Scripting Guru
*****


Posts: 8336
Reputation: 109
39 / Male / Flag
Joined: Dec 2002
Status: Away
RE: [HELP] Browsing to save a file
quote:
Originally posted by SmokingCookie
I don't understand those flags etc., but here's the code anyway:
Looking at the MSDN documentation for a structure is always a wise idea: http://msdn.microsoft.com/en-us/library/ms646839(VS.85).aspx

code:
function BrowseFile(filter, title, file) {
    var _SAVEFILENAME = Interop.Allocate(88);
    var s_filter;
    var s_file;
    var s_title;
    with(_SAVEFILENAME) {
        /*Define the size of the structure; this is done because there are multiple sizes of the structure */
        WriteDWORD(0, Size);
       
        /*Use this portion to force the Dialog to show ontop of another window */
        WriteDWORD(4, 0);
       
        /*Define the file filter */
        s_filter = Interop.Allocate(2 * filter.length + 1);
        WriteMultiStringW(s_filter, filter);
        WriteDWORD(12, s_filter.DataPtr);
       
        /* Set the current selected filter as the first filter in the list */
        WriteDWORD(24, 1);
       
        /* Allocate space to hold the filename */
        s_file = Interop.Allocate(512);
        s_file.WriteString(0, file);
        WriteDWORD(28, s_file.DataPtr);
       
        /* Set the maximum size of the file path */
        WriteDWORD(32, 512);
       
        /* Set the title of the dialog */
        s_title = Interop.Allocate(2 * title.length + 1);
        s_title.WriteString(0, title);
        WriteDWORD(48, s_title.DataPtr);
       
        /* Set the flags for the dialog style */
        WriteDWORD(52, OFN_ENABLESIZING | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_PATHMUSTEXIST);
    }
    /* Call the function */
    var ret = Interop.Call('comdlg32', 'GetSaveFileNameW', _SAVEFILENAME);
    //return
            // if ret = 0
                       // since ret == 0 is true return '__none'
                                  // since ret != 0 then return the filename

    return ret === 0 ? '__none' : s_file.ReadString(0);
}

This is untested code. You need to learn to start doing things yourself.

This post was edited on 05-25-2008 at 04:30 PM by matty.
05-21-2008 12:29 AM
Profile E-Mail PM Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On