Shoutbox

Creating file dialog in Vista - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Creating file dialog in Vista (/showthread.php?tid=91855)

Creating file dialog in Vista by tribbium on 08-13-2009 at 01:40 AM

For some reason, i'm getting reports that the following code for creating file dialogs doesn't work in Vista. This was taken from MPScripts.net and replaced some old code using the windows API. Can anyone confirm this error as my whole house is full of XPs.

code:
function browseForFile (){
    var BrowseFilter = "Text Files (*.txt)|*.txt|All Files|*.*";
    var BrowseDialog = new ActiveXObject("UserAccounts.CommonDialog");
    BrowseDialog.Filter = BrowseFilter;
    BrowseDialog.Flags = "&H4";
    BrowseDialog.ShowOpen()
    return BrowseDialog.FileName;
}

RE: Creating file dialog in Vista by Matti on 08-13-2009 at 07:45 AM

Those ActiveXObjects are very system-dependent, Vista and above no longer support those. You're much better off using native Win32 functions, as those are kept throughout many versions of Windows.

In the case of an open file dialog, you'll have to create an OPENFILENAME memory structure and then call GetOpenFileName to open the dialog and receive the results.

Luckily for you, there is already an implementation of this available for Plus! Live, so go have a look at Matti's reply to CommonDialog help! Here is an example of your code, written for the BrowseForFile() function.

Javascript code:
function MyBrowseForFile() {
    return BrowseForFile(
        "Select a file to open",                    //Dialog title
        "C:\\",                                     //Start directory
        "Text Files (*.txt)|*.txt|All Files|*.*||", //Filters
        false                                       //True = save, false = open
    ); //Returns the selected path, or false if the dialog was canceled
}


RE: Creating file dialog in Vista by tribbium on 08-13-2009 at 09:45 PM

thanks for confirming it! I guess I'll just go and do a code revert =P