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.