function MySHDPath5(mindex:longint):string; function BrowseCallbackProc(hwnd:HWND;uMsg:UINT;lp:LPARAM;pData:LPARAM ):longint; stdcall;
implementation
function MySHDPath5(mindex:longint):string; var BrowseInfo: TBrowseInfo; DisplayName: array[0..MAX_PATH] of char; idBrowse,idl : PItemIDList; tmp : PChar; i:longint; begin Result:='; try Getmem(tmp, 255); i:=sizeof(longint); SHGetSpecialFolderLocation(application.Handle,mindex, idl); with BrowseInfo do begin hWndOwner:=application.Handle; pidlRoot:=idl; pszDisplayName:=DisplayName; lpszTitle:='目录选择'; ulFlags:=BIF_STATUSTEXT+80; lpfn:=@BrowseCallbackProc; lParam:=0; end; idBrowse:=SHBrowseForFolder(BrowseInfo); if assigned(idBrowse) then Begin SHGetPathFromIDList(idBrowse,tmp); Result :=strpas(tmp); end; finally Freemem(tmp); end; end;
function BrowseCallbackProc(hwnd:HWND;uMsg:UINT;lp:LPARAM;pData:LPARAM ):longint; var dirbuf: array[0..Max_Path-1] of Char; begin Result := 0; if uMsg = BFFM_INITIALIZED then begin if GetCurrentDirectory(Max_path,@dirbuf) > 0 then // WParam is TRUE since you are passing a path. // It would be FALSE if you were passing a pidl. SendMessage(hwnd,BFFM_SETSELECTION,1,LongInt(@Dirbuf)); end else if uMsg = BFFM_SELCHANGED then begin
// Set the status window to the currently selected path. if SHGetPathFromIDList(PItemIDList(lp) ,@Dirbuf) then // SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,LongInt(@Dirbuf)); SendMessage(hwnd,BFFM_SETSELECTION,1,LongInt(@Dirbuf)); end; end;