프로그래밍/델파이

폴더 선택 대화상자 띄우기

채윤아빠 2007. 12. 22. 00:18
728x90
반응형


uses ActiveX, ShlObj, ...;

// ...

var
  pidl, pidlSelected: PItemIDList;
  ABrowserInfo: TBrowseInfo;
  szDirName: array [0..260] of AnsiChar;
begin
  {Get the root PIDL of the network neighborhood tree}
  if SHGetSpecialFolderLocation(Handle, CSIDL_DESKTOP, pidl) = NOERROR then
  begin
    {Populate a BROWSEINFO structure}
    ABrowserInfo.hwndOwner      :=Handle;
    ABrowserInfo.pidlRoot       :=pidl;
    ABrowserInfo.pszDisplayName :=szDirName;
    ABrowserInfo.lpszTitle      :='Select directory';
    ABrowserInfo.ulFlags        :=BIF_RETURNONLYFSDIRS or BIF_NEWDIALOGSTYLE;
    ABrowserInfo.lpfn           :=nil;
    ABrowserInfo.lParam         :=0;
    ABrowserInfo.iImage         :=- 1;
    {Display the "Browse For Folder" dialog box}
    pidlSelected := SHBrowseForFolder(ABrowserInfo);
    {NULL indicates that Cancel was selected from the dialog box}
    if pidlSelected <> nil then
    begin
      SHGetPathFromIDList(pidlSelected, szDirName);
      // szDirName 처리...

      {Release the PIDL of the computer name}
      CoTaskMemFree(pidlSelected);
    end;
    {Release the PIDL of the network neighborhood tree}
    CoTaskMemFree(pidl);
  end;