Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: PowerBuilder
Expertise: Beginner
Oct 18, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Creating a "Browse for Folder" Dialog Box

How can I create a "browse" facility in my application—something which throws up a dialog box that allows the user to view folders and select one, as in Microsoft Explorer, without selecting a specific file within it?

This is not a built-in feature of PowerBuilder; it requires the use of the Windows API. To begin with, create a new non-visual object and create the following local structures:

structure shitemid 
unsignedint        cb
character        abid

structure itemidlist
shitemid        mkid

structure browseinfo
unsignedlong        howner
unsignedlong        pidlroot
string        pszdisplayname
string        lpsztitle
unsignedint        ulflags
unsignedlong        lpfn
long        lparam
integer        iimage
Add the following API calls to the local external functions:
Function unsignedlong &
   SHGetPathFromIDListA( unsignedlong pidl, ref string pszPath) Library 'shell32'
Function unsignedlong &
   SHBrowseForFolderA( browseinfo lpbrowseinfo ) Library 'shell32'
Subroutine CoTaskMemFree( ulong idlist ) Library 'ole32'
Create a function with the following arguments and return value:
string browseforfolder (window awi_parent, string as_caption)
In this function add the following code:
browseinfo lstr_bi
itemidlist lstr_idl
unsignedlong ll_pidl
unsignedlong ll_r
Integer li_pos
String ls_Path
unsignedlong ll_Null

SetNull( ll_Null )

lstr_bi.hOwner = Handle( awi_Parent )
lstr_bi.pidlRoot = 0
lstr_bi.lpszTitle = as_caption
lstr_bi.ulFlags = 1
lstr_bi.pszDisplayName = Space( 255 )
lstr_bi.lpfn = ll_Null

ll_pidl = SHBrowseForFolderA( lstr_bi )

ls_Path = Space( 255 )
ll_R = SHGetPathFromIDListA( ll_pidl, ls_Path )

CoTaskMemFree( ll_pidl )

RETURN ls_Path
Save the object and in your script, create the object call the browseforfolder function, and then destroy the object.
DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date