Powerbuilder – Folder Selection Dialog Window

Posted on Thursday, June 23rd, 2011 at 8:20 pm in

Here is an NVO used to envoke a Windows folder selection dialog since Powerbuilder does not have it’s own version. You can change the API calls to ANSI for earlier versions of PB. I’ve had this squirreled away for awhile and I no doubt got it from someone else off the web. Thanks!

// window event script with string parameter
// string parameter is the caption on the folder selection dialog window

uo_select_folder luo_folder
// iw_parent set somewhere else on the window
RETURN luo_folder.uf_browseforfolder( iw_parent, as_caption)

Export for non visual object. Uses Unicode API calls.

$PBExportHeader$uo_select_folder.sru
forward
global type uo_select_folder from nonvisualobject
end type
type str_itemid from structure within uo_select_folder
end type
type str_itemidlist from structure within uo_select_folder
end type
type str_browseinfo from structure within uo_select_folder
end type
end forward

type str_itemid from structure
	unsignedint		db
	character		abid
end type

type str_itemidlist from structure
	str_itemid		mkid
end type

type str_browseinfo from structure
	unsignedlong		howner
	unsignedlong		pidlroot
	string		pszdisplayname
	string		lpsztitle
	unsignedinteger		ulflags
	unsignedlong		lpfn
	long		lparm
	integer		iimage
end type

global type uo_select_folder from nonvisualobject autoinstantiate
end type

type prototypes
 Function unsignedlong SHGetPathFromIDListW( unsignedlong pidl, ref string pszPath) Library 'shell32'
Function unsignedlong SHBrowseForFolderW( str_browseinfo lpstr_browseinfo ) Library 'shell32'
Subroutine CoTaskMemFree( ulong idlist ) Library 'ole32'
end prototypes
forward prototypes
public function string uf_browseforfolder (ref window awi_parent, string as_caption)
end prototypes

public function string uf_browseforfolder (ref window awi_parent, string as_caption);str_browseinfo lstr_bi
str_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 = SHBrowseForFolderW( lstr_bi )

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

CoTaskMemFree( ll_pidl )

RETURN ls_Path
end function

on uo_select_folder.create
call super::create
TriggerEvent( this, "constructor" )
end on

on uo_select_folder.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on

Add your comment

Leave a Reply

Top