$PBExportHeader$nvo_dir_browser.sru
$PBExportComments$Shell32 API functions
forward
global type nvo_dir_browser from nonvisualobject
end type
type browseinfo from structure within nvo_dir_browser
end type
end forward
type BROWSEINFO from structure
long hwndOwner
long pidlRoot
string pszDisplayName
string lpszTitle
ulong ulFlags
ulong lpfn
ulong lParam
long iImage
end type
global type nvo_dir_browser from nonvisualobject autoinstantiate
end type
type prototypes
// Shell functions
Function long SHBrowseForFolder( Ref BROWSEINFO lpBi ) Library "shell32.dll"
Function boolean SHGetPathFromIDList( long pIDL, Ref String pszPath ) Library "shell32.dll" Alias For "SHGetPathFromIDListA"
end prototypes
type variables
// MAX_PATH constant for file operations
Private constant long MAX_PATH = 260
// SHBrowseForFolder constants
Private:
constant ulong BIF_RETURNONLYFSDIRS = 1 // Browse for directory
constant ulong BIF_DONTGOBELOWDOMAIN = 2 // For starting the Find Computer
constant ulong BIF_STATUSTEXT = 4
constant ulong BIF_RETURNFSANCESTORS = 8
constant ulong BIF_EDITBOX = 16
constant ulong BIF_BROWSEFORCOMPUTER = 4096 // Browse for computer
constant ulong BIF_BROWSEFORPRINTER = 8192 // Browse for printers
constant ulong BIF_BROWSEINCLUDEFILES = 16384 // Browse for everything
end variables
forward prototypes
public function string of_browseforfolder (long alhparent, string asprompt)
private function string of_shbrowseforfolder (long alhparent, string asprompt, long alflags)
end prototypes
public function string of_browseforfolder (long alhparent, string asprompt);
//===================================================================
// Function: of_BrowseForFolder()
//-------------------------------------------------------------------
// Description:Macro function to call of_SHBrowseForFolder with correct
// BIF_xxx constant
//-------------------------------------------------------------------
// Parameters: alhParent (LONG)
// asPrompt (STRING)
// alhParent
// Handle of the owner window for the dialog box.
// asPrompt
// Text to go in the banner over the tree.
//-------------------------------------------------------------------
// Returns: Returns the selected folder name.
//===================================================================
RETURN This.of_SHBrowseForFolder( alhParent, asPrompt, BIF_RETURNONLYFSDIRS )
end function
private function string of_shbrowseforfolder (long alhparent, string asprompt, long alflags);
//===================================================================
// Function: of_SHBrowseForFolder()
//-------------------------------------------------------------------
// Description:Displays a dialog box that enables the user to select
// a shell folder.
//-------------------------------------------------------------------
// Parameters: alhParent (LONG)
// asPrompt (STRING)
// alFlags (LONG)
// alhParent
// Handle of the owner window for the dialog box.
// asPrompt
// Text to go in the banner over the tree.
// alFlags
// A combination of the BIF_xxx constant flags
//-------------------------------------------------------------------
// Returns: Returns the folder/printer/computer name.
//===================================================================
long llIDList
BROWSEINFO lBI
string lsPath
// Populate the BROWSEINFO structure
lBI.hWndOwner = alhParent // Handle of parent window
lBI.pidlRoot = 0 // Use default namespace root
lBI.pszDisplayName = Space( MAX_PATH ) // Allocate space for the returned buffer
lBI.lpszTitle = asPrompt // Text to go in the banner above the tree
lBI.ulFlags = alFlags // BIF_xxx flags
lBI.lpfn = 0 // No callback function
lBI.lParam = 0 // Extra info for callbacks
lBI.iImage = 0 // Output var: where to return the Image index
// SHBrowseForFolder returns a pointer to an item identifier list that
// specifies the location of the selected folder.
llIDList = SHBrowseForFolder( lBI )
IF (llIDList > 0) THEN
// Allocate space before calling API function
lsPath = Space( MAX_PATH )
// Extract path name from IDList
IF NOT SHGetPathFromIDList( llIDList, lsPath ) THEN
// Error extracting path
lsPath = ""
END IF
ELSE
// User pressed CANCEL, or error in selecting path
lsPath = ""
END IF
RETURN Trim(lsPath)
end function
on nvo_dir_browser.create
call super::create
TriggerEvent( this, "constructor" )
end on
on nvo_dir_browser.destroy
TriggerEvent( this, "destructor" )
call super::destroy
end on
event constructor;
//Demo
/*
string lsDestination
nvo_browser luoShell
lsDestination = upper(luoShell.of_BrowseForFolder(Handle(This), "选择上报数据库存放路径:"));
IF Len(lsDestination) > 0 THEN
if right(lsDestination,1) <> '\' then lsDestination = lsDestination + '\';
END IF
*/
end event
Pointer to a BROWSEINFO structure that contains information used to display the dialog box.
Return Values
Returns a pointer to an item identifier list that specifies the location of the selected folder relative to the root of the name space. If the user chooses the Cancel button in the dialog box, the return value is NULL.
The calling application is responsible for freeing the returned item identifier list using the shell's task allocator.