Главная страница | назад





Article #17008: Using the Shell API function SHBrowseForFolder()

 Question and Answer Database

FAQ2008D.txt   Using the Shell API function SHBrowseForFolder() 
Category   :Windows API
Platform    :All
Product    :All 32 bit  

Question:
How can I use the Shell API function SHBrowseForFolder() to
let the user browse for a folder?


Answer:
The following example demonstrates using the SHBrowseForFolder()
function to allow the user to select a given directory object.

Example:

uses ShellAPI, ShlObj;

procedure TForm1.Button1Click(Sender: TObject);
var
  TitleName : string;
  lpItemID : PItemIDList;
  BrowseInfo : TBrowseInfo;
  DisplayName : array[0..MAX_PATH] of char;
  TempPath : array[0..MAX_PATH] of char;
begin
  FillChar(BrowseInfo, sizeof(TBrowseInfo), #0);
  BrowseInfo.hwndOwner := Form1.Handle;
  BrowseInfo.pszDisplayName := @DisplayName;
  TitleName := 'Please specify a directory';
  BrowseInfo.lpszTitle := PChar(TitleName);
  BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS;
  lpItemID := SHBrowseForFolder(BrowseInfo);
  if lpItemId <> nil then begin
    SHGetPathFromIDList(lpItemID, TempPath);
    ShowMessage(TempPath);
    GlobalFreePtr(lpItemID);
  end;
end;


7/16/98 4:31:28 PM
 

Last Modified: 01-SEP-99