benpoole.com

“It is a very sad thing that nowadays there is so little useless information.”

Lotusscript version of LocalBrowse

Written by Ben Poole on 01 Nov 2002
Categories / keywords: Win32 API, Lotusscript
(click on a term to search for related articles at this site)

Add a comment...



Introduction

There's an undocumented @Prompt which allows the user to browse for a local folder: @Prompt([LocalBrowse]). I can't remember if this is implemented in NotesUIWorkspace.Prompt. So here's my Lotusscript version of this code. It's a function which returns a string. This string will be the full path to the folder, and you can then use this in your code as appropriate. The only thing you might want to change is the prompt, held in the property mBrowseInfo.lpszTitle.

The code uses Win32 function calls, so obviously it's only for that platform. I've tested this in Notes 5.05 on a machine running Windows 2000 Professional, so YMMV. The attachment comprises this exact same code in the form of a script library — you should be able to do a File / Import directly into the programming pane of a new script library, selecting this file along the way. I also show you an example call below.

Here are the bits of code which should go in your (Declarations) section. The first block defines the structure of BrowseInfo whilst the remaining blocks are function declarations used in the code. Note the use of GetActiveWindow. This is a particularly common function for anyone doing Win32 code in Lotusscript, as you need a handle on the window invoking your code in practically all such programming. The other functions provide interfaces to the actual folder browser mechanism in Windows, and also a function to help with grabbing the folder ID. You can find out more about these functions at the following URLs:

' // Win32 function to get handle on current window
Declare Function GetActiveWindow Lib "user32.dll" () As Long

' // BrowseInfo stucture
Type BROWSEINFO
hwndOwner 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


' // BrowseFlags constants
Const BIF_BROWSEFORCOMPUTER = 1000
Const BIF_BROWSEFORPRINTER = 2000
Const BIF_DONTGOBELOWDOMAIN = 2
Const BIF_RETURNFSANCESTORS = 8
Const BIF_RETURNONLYFSDIRS = 1
Const BIF_STATUSTEXT = 4

Const MAX_SIZE = 255

' // Win32 function to browse for a folder, rather than a file or files
Declare Function BrowseFolderDlg Lib "shell32.dll" Alias "SHBrowseForFolder" (lpBrowseInfo As BROWSEINFO) As Long

' // Win32 function that returns the path of the folder selected
Declare Function GetPathFromIDList Lib "shell32.dll" Alias "SHGetPathFromIDList"_
(Byval PointerToIDList As Long, Byval pszPath As String) As Long

Now I'll list the main body of the code, i.e. the Lotusscript function. First, here's an example call:

Dim strFolderPath As String
strFolderPath = BrowseForFolder()
Messagebox "The folder you chose is '" & strFolderPath & "'.", 0, "LocalBrowse"

Function BrowseForFolder() As String
Dim mBrowseInfo As BROWSEINFO
Dim lngPointerToIDList As Long
Dim lngResult As Long
Dim strPathBuffer As String
Dim strReturnPath As String
Dim vbNullChar As String

vbNullChar = Chr(0)

On Error Goto lblErrs

mBrowseInfo.hwndOwner = GetActiveWindow()

' // Set the default folder for the dialog box (0 = My Computer,
' // 5 = My Documents)
mBrowseInfo.pidlRoot = 0

mBrowseInfo.lpszTitle = "Select the folder you wish to use:"
' // Pointer to a buffer that receives the display name
' // of the folder selected by the user
mBrowseInfo.pszDisplayName = String(MAX_SIZE, Chr(0))
' // Value specifying the types of folders to be listed
' // in the dialog box as well as other options
mBrowseInfo.ulFlags = BIF_RETURNONLYFSDIRS

' // Returns a pointer to an item identifier list that
' // specifies the location of the selected folder relative
' // to the root of the name space
lngPointerToIDList = BrowseFolderDlg(mBrowseInfo)

If lngPointerToIDList <> 0& Then
' // Create a buffer
strPathBuffer = String(MAX_SIZE, Chr(0))

' // Now get the selected path
lngResult = GetPathFromIDList(Byval lngPointerToIDList, Byval strPathBuffer)
' // And return just that
strReturnPath = Left$(strPathBuffer, Instr(strPathBuffer, vbNullChar) - 1)
End If

BrowseForFolder = strReturnPath

lblEnd:
Exit Function

lblErrs:
Messagebox "Unexpected error: " & Error$ & " (" & Cstr(Err) & ").", 0, "Error"
Resume lblEnd
End Function


Further reading:


Attachment(s): libLocalBrowse.lss (2 KB)

   » Lotusscript version of LocalBrowse (Ben Poole 01 Nov 2002)
   ... Re: Lotusscript version of LocalBrowse (Jonathon Thomas... 15 Nov 2002)
   ... Response to Jonathon (Ben Poole 15 Nov 2002)
   ... Re: Lotusscript version of LocalBrowse (Ralph 17 Feb 2003)
   ... Re: Lotusscript version of LocalBrowse (Dan 1 Apr 2003)
   ... Grrreat!!! (P 15 May 2003)
   RE: Lotusscript version of LocalBrowse (Fred 20 Jul 2004)
   RE: Lotusscript version of LocalBrowse (Chris Crompton 5 May 2005)
   RE: Lotusscript version of LocalBrowse (Ben Poole 6 May 2005)
   RE: Lotusscript version of LocalBrowse (Sjef Bosman 5 Mar 2006)

Add a comment...