'SelectDirectory'에 해당되는 글 2건

  1. 2012.10.23 SelectDirectory 확장
  2. 2012.10.23 SelectDirectory 원하는 위치에 띄우기
 
uses 
ShlObj, ActiveX;

{ 
This code shows the SelectDirectory dialog with additional expansions: 
- an edit box, where the user can type the path name, 
- also files can appear in the list, 
- a button to create new directories. 


Dieser Code zeigt den SelectDirectory-Dialog mit zusatzlichen Erweiterungen: 
- eine Edit-Box, wo der Benutzer den Verzeichnisnamen eingeben kann, 
- auch Dateien konnen in der Liste angezeigt werden, 
- eine Schaltflache zum Erstellen neuer Verzeichnisse. 
} 

function AdvSelectDirectory(const Caption: string; const Root: WideString; 
var Directory: string; EditBox: Boolean = False; ShowFiles: Boolean = False; 
AllowCreateDirs: Boolean = True): Boolean; 
// callback function that is called when the dialog has been initialized 
//or a new directory has been selected 

// Callback-Funktion, die aufgerufen wird, wenn der Dialog initialisiert oder 
//ein neues Verzeichnis selektiert wurde 
  function SelectDirCB(Wnd: HWND; uMsg: UINT; lParam, lpData: lParam): Integer; stdcall;
  var
    PathName: array[0..MAX_PATH] of Char;
  begin 
    case uMsg of
      BFFM_INITIALIZED: SendMessage(Wnd, BFFM_SETSELECTION, Ord(True), Integer(lpData));
      // include the following comment into your code if you want to react on the
      //event that is called when a new directory has been selected
      // binde den folgenden Kommentar in deinen Code ein, wenn du auf das Ereignis
      //reagieren willst, das aufgerufen wird, wenn ein neues Verzeichnis selektiert wurde
      {BFFM_SELCHANGED:
      begin
      SHGetPathFromIDList(PItemIDList(lParam), @PathName);
      // the directory "PathName" has been selected
      // das Verzeichnis "PathName" wurde selektiert
      end;}
    end; 
    Result := 0;
  end;
var 
  WindowList: Pointer;
  BrowseInfo: TBrowseInfo;
  Buffer: PChar;
  RootItemIDList, ItemIDList: PItemIDList;
  ShellMalloc: IMalloc;
  IDesktopFolder: IShellFolder;
  Eaten, Flags: LongWord;
const
  // necessary for some of the additional expansions
  // notwendig fur einige der zusatzlichen Erweiterungen
  BIF_USENEWUI = $0040;
  BIF_NOCREATEDIRS = $0200;
begin 
  Result := False;
  if not DirectoryExists(Directory) then 
    Directory := '';

  FillChar(BrowseInfo, SizeOf(BrowseInfo), 0); 
  if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then 
  begin
    Buffer := ShellMalloc.Alloc(MAX_PATH);
    try
      RootItemIDList := nil;
      if Root <> '' then 
      begin 
        SHGetDesktopFolder(IDesktopFolder);
        IDesktopFolder.ParseDisplayName(Application.Handle, nil,
        POleStr(Root), Eaten, RootItemIDList, Flags);
      end; 

      OleInitialize(nil);

      with BrowseInfo do 
      begin 
        hwndOwner := Application.Handle;
        pidlRoot := RootItemIDList;
        pszDisplayName := Buffer;
        lpszTitle := PChar(Caption);
        // defines how the dialog will appear:
        // legt fest, wie der Dialog erscheint:
        ulFlags := BIF_RETURNONLYFSDIRS or BIF_USENEWUI or
        BIF_EDITBOX * Ord(EditBox) or BIF_BROWSEINCLUDEFILES * Ord(ShowFiles) or
        BIF_NOCREATEDIRS * Ord(not AllowCreateDirs);
        lpfn := @SelectDirCB;
        if Directory <> '' then
          lParam := Integer(PChar(Directory));
      end;

      WindowList := DisableTaskWindows(0);
      try
        ItemIDList := ShBrowseForFolder(BrowseInfo);
      finally
        EnableTaskWindows(WindowList);
      end;

      Result := ItemIDList <> nil;

      if Result then
      begin
        ShGetPathFromIDList(ItemIDList, Buffer);
        ShellMalloc.Free(ItemIDList);
        Directory := Buffer;
      end;
    finally 
      ShellMalloc.Free(Buffer);
    end;
  end;
end; 


// Example: 
procedure TForm1.Button1Click(Sender: TObject); 
var 
  dir: string;
begin
  AdvSelectDirectory('Caption', 'c:\', dir, False, False, True);
  Label1.Caption := dir;
end; 


'APP > 파일관련' 카테고리의 다른 글

SelectDirectory 원하는 위치에 띄우기  (0) 2012.10.23
폴더 복사,이동,삭제  (0) 2012.10.23
파일 버전 구하기  (0) 2012.10.23
부모풀더까지 한방에 만들기  (0) 2012.10.23
Posted by ezmind
:
 
uses Math, ShlObj, ActiveX;

function SelectDirectoryEx(const Caption: string; const Root: string;
  out Directory: string; AX, AY: Integer): Boolean;

  type
  PBFFRecord = ^TBFFRecord;

  TBFFRecord = record
  InitDir: PChar;
  X: Integer;
  Y: Integer;
  end;

var
  BFFR:TBFFRecord;
  IDList: PItemIDList;
  BrowseInfo: TBrowseInfo;
  Malloc:IMalloc;
  WindowList: Pointer;
  Buffer: PChar;


  function BrowseFolderProc(hWindow: HWND; uMsg: UINT; lParam: LPARAM;
    lpData: LPARAM): Integer; stdcall;
  var
    PathName: array[0..MAX_PATH] of Char;
    PBFFR:PBFFRecord;
    r: TRect;
    x, y, cx, cy, w, h: Integer;

  begin
    case uMsg of
      BFFM_INITIALIZED:
        begin
          PBFFR := Pointer(lpData);
          if lstrlen(PBFFR^.InitDir) > 1 then
            SendMessage(hWindow,BFFM_SETSELECTION, 1, Integer(PBFFR^.InitDir));

          cx := GetSystemMetrics(SM_CXSCREEN);
          cy := GetSystemMetrics(SM_CYSCREEN);
          GetWindowRect(hWindow, r);
          w := r.Right - r.Left;
          h := r.Bottom - r.Top;
          x := PBFFR^.X;
          y := PBFFR^.Y;

          if (x = 0) or (y = 0) then
          begin
            x := (cx - w) div 2;
            y := (cy - h) div 2;
          end;

          x := Max(Min(x, cx - w), 0);
          y := Max(Min(y, cy - h), 0);

          SetWindowPos(hWindow, 0, x, y, 0, 0, SWP_NOSIZE or SWP_NOZORDER);
        end;
      BFFM_SELCHANGED:
        begin
          SHGetPathFromIDList(PItemIDList(lParam), @PathName);
          SendMessage(hWindow, BFFM_SETSTATUSTEXT, 0, LongInt(PChar(@PathName)));
        end;
    end;
    Result := 0;
  end;
begin
  Result := False;
  Directory := '';
  BFFR.InitDir := PChar(Root);
  BFFR.X := AX;
  BFFR.Y := AY;
  FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);

  if (ShGetMalloc(Malloc) = S_OK) and (Malloc <> nil) then
  begin
  Buffer := Malloc.Alloc(MAX_PATH);
  try
    with BrowseInfo do
    begin
      hwndOwner := Application.Handle;
      pidlRoot := nil;
      pszDisplayName := Buffer;
      lpszTitle := PChar(Caption);
      ulFlags := BIF_STATUSTEXT or BIF_RETURNONLYFSDIRS;
      lpfn := @BrowseFolderProc;
      lParam := Integer(@BFFR);
    end;
    WindowList := DisableTaskWindows(0);
    try
      IDList := ShBrowseForFolder(BrowseInfo);
    finally
      EnableTaskWindows(WindowList);
    end;
    Result := IDList <> nil;
    if Result then
    begin
      ShGetPathFromIDList(IDList, Buffer);
      Malloc.Free(IDList);
      Directory := Buffer;
    end;
    finally
      Malloc.Free(Buffer);
    end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
begin
  if SelectDirectoryEx('폴더를 선택해 주세요', 'C:\Windows', s, 300, 300) then
  Label1.Caption := s;

  if SelectDirectoryEx('화면의 한가운데', 'C:\Windows', s, 0, 0) then
  Label1.Caption := s;


end;


'APP > 파일관련' 카테고리의 다른 글

SelectDirectory 확장  (0) 2012.10.23
폴더 복사,이동,삭제  (0) 2012.10.23
파일 버전 구하기  (0) 2012.10.23
부모풀더까지 한방에 만들기  (0) 2012.10.23
Posted by ezmind
: