Shoutbox

[?] Select Folder (CmnDlg) - 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: [?] Select Folder (CmnDlg) (/showthread.php?tid=81578)

[?] Select Folder (CmnDlg) by Spunky on 02-11-2008 at 12:58 AM

Can anybody offer any advice... I found this code, but I'm not great at understanding structures and how to use them etc. Can someone give me a version of this for JScript or a better way of doing it?

code:
'************** Code Start **************
'This code was originally written by Terry Kreft.
'It is not to be altered or distributed,
'except as part of an application.
'You are free to use it in any application,
'provided the copyright notice is left unchanged.
'
'Code courtesy of
'Terry Kreft

Private Type BROWSEINFO
  hOwner As Long
  pidlRoot As Long
  pszDisplayName As String
  lpszTitle As String
  ulFlags As Long
  lpfn As Long
  lParam As Long
  iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" Alias _
            "SHGetPathFromIDListA" (ByVal pidl As Long, _
            ByVal pszPath As String) As Long
           
Private Declare Function SHBrowseForFolder Lib "shell32.dll" Alias _
            "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) _
            As Long
           
Private Const BIF_RETURNONLYFSDIRS = &H1
Public Function BrowseFolder(szDialogTitle As String) As String
  Dim X As Long, bi As BROWSEINFO, dwIList As Long
  Dim szPath As String, wPos As Integer
 
    With bi
        .hOwner = hWndAccessApp
        .lpszTitle = szDialogTitle
        .ulFlags = BIF_RETURNONLYFSDIRS
    End With
   
    dwIList = SHBrowseForFolder(bi)
    szPath = Space$(512)
    X = SHGetPathFromIDList(ByVal dwIList, ByVal szPath)
   
    If X Then
        wPos = InStr(szPath, Chr(0))
        BrowseFolder = Left$(szPath, wPos - 1)
    Else
        BrowseFolder = vbNullString
    End If
End Function
'*********** Code End *****************


RE: [?] Select Folder (CmnDlg) by MeEtc on 02-11-2008 at 01:03 AM

MPScripts has a snippet of code that might help you out a bit more
http://mpscripts.net/code.php?id=1

code:
var BrowseInfo = Interop.Allocate(32);
BrowseInfo.WriteDWORD(0, 0); //hOwner
BrowseInfo.WriteDWORD(4, 0); //pidlRoot
var foldertitle = Interop.Allocate((255+1) * 2);
BrowseInfo.WriteDWORD(8, foldertitle.DataPtr);
var sTitle = 'Test Window Title';
var pTitle = Interop.Allocate((sTitle.length+1) * 2);
pTitle.WriteString(0, sTitle, false);
BrowseInfo.WriteDWORD(12, pTitle.DataPtr);
BrowseInfo.WriteDWORD(16, 1); //ulFlags
BrowseInfo.WriteDWORD(20, 0); //lpfn
BrowseInfo.WriteDWORD(24, 0); //lparam
BrowseInfo.WriteDWORD(28, 0); //iImage
var pidl = Interop.Call('shell32', 'SHBrowseForFolder', BrowseInfo);
var folderpath = Interop.Allocate((255+1) * 2);
Interop.Call('shell32', 'SHGetPathFromIDList', pidl, folderpath);
Debug.Trace('Folder Path: ' + folderpath.ReadString(0, false));
Debug.Trace('Folder Title: ' + foldertitle.ReadString(0, false));

RE: [?] Select Folder (CmnDlg) by Spunky on 02-11-2008 at 01:09 AM

Thats awesome. Thanks for quick reply