各位如何像迅雷那样,打开下载文件所在的文件夹,并且把焦点移到指定文件上?50分相送(50分)

  • 主题发起人 主题发起人 monkey_cn
  • 开始时间 开始时间
M

monkey_cn

Unregistered / Unconfirmed
GUEST, unregistred user!
各位如何像迅雷那样,打开下载文件所在的文件夹,并且把焦点移到指定文件上?50分相送
 
Uses <br> &nbsp;ShellAPI;<br>ShellExecute(0, nil, PChar('explorer.exe'),PChar('/e, '+ '/select, ' + '你要选定的文件'), nil, SW_NORMAL);
 
function SelectDirCB(Wnd: HWND; uMsg: UINT; lParam, lpData: LPARAM): Integer stdcall;<br>begin<br> &nbsp;if (uMsg = BFFM_INITIALIZED) and (lpData &lt;&gt; 0) then<br> &nbsp; &nbsp;SendMessage(Wnd, BFFM_SETSELECTION, Integer(True), lpdata);<br> &nbsp;result := 0;<br>end;<br><br>function SelectDirectory(const Caption: string; const Root: WideString;<br> &nbsp;var Directory: string): Boolean;<br>var<br> &nbsp;WindowList: Pointer;<br> &nbsp;BrowseInfo: TBrowseInfo;<br> &nbsp;Buffer: PChar;<br> &nbsp;OldErrorMode: Cardinal;<br> &nbsp;RootItemIDList, ItemIDList: PItemIDList;<br> &nbsp;ShellMalloc: IMalloc;<br> &nbsp;IDesktopFolder: IShellFolder;<br> &nbsp;Eaten, Flags: LongWord;<br>begin<br> &nbsp;Result := False;<br> &nbsp;if not DirectoryExists(Directory) then<br> &nbsp; &nbsp;Directory := '';<br> &nbsp;FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br> &nbsp;if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc &lt;&gt; nil) then<br> &nbsp;begin<br> &nbsp; &nbsp;Buffer := ShellMalloc.Alloc(MAX_PATH);<br> &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp;RootItemIDList := nil;<br> &nbsp; &nbsp; &nbsp;if Root &lt;&gt; '' then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;SHGetDesktopFolder(IDesktopFolder);<br> &nbsp; &nbsp; &nbsp; &nbsp;IDesktopFolder.ParseDisplayName(Application.Handle, nil,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;POleStr(Root), Eaten, RootItemIDList, Flags);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;with BrowseInfo do<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;hwndOwner := Application.Handle;<br> &nbsp; &nbsp; &nbsp; &nbsp;pidlRoot := RootItemIDList;<br> &nbsp; &nbsp; &nbsp; &nbsp;pszDisplayName := Buffer;<br> &nbsp; &nbsp; &nbsp; &nbsp;lpszTitle := PChar(Caption);<br> &nbsp; &nbsp; &nbsp; &nbsp;ulFlags := BIF_RETURNONLYFSDIRS;<br> &nbsp; &nbsp; &nbsp; &nbsp;if Directory &lt;&gt; '' then<br> &nbsp; &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lpfn := SelectDirCB;<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lParam := Integer(PChar(Directory));<br> &nbsp; &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;WindowList := DisableTaskWindows(0);<br> &nbsp; &nbsp; &nbsp;OldErrorMode := SetErrorMode(SEM_FAILCRITICALERRORS);<br> &nbsp; &nbsp; &nbsp;try<br> &nbsp; &nbsp; &nbsp; &nbsp;ItemIDList := ShBrowseForFolder(BrowseInfo);<br> &nbsp; &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp; &nbsp;SetErrorMode(OldErrorMode);<br> &nbsp; &nbsp; &nbsp; &nbsp;EnableTaskWindows(WindowList);<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp; &nbsp;Result := &nbsp;ItemIDList &lt;&gt; nil;<br> &nbsp; &nbsp; &nbsp;if Result then<br> &nbsp; &nbsp; &nbsp;begin<br> &nbsp; &nbsp; &nbsp; &nbsp;ShGetPathFromIDList(ItemIDList, Buffer);<br> &nbsp; &nbsp; &nbsp; &nbsp;ShellMalloc.Free(ItemIDList);<br> &nbsp; &nbsp; &nbsp; &nbsp;Directory := Buffer;<br> &nbsp; &nbsp; &nbsp;end;<br> &nbsp; &nbsp;finally<br> &nbsp; &nbsp; &nbsp;ShellMalloc.Free(Buffer);<br> &nbsp; &nbsp;end;<br> &nbsp;end;<br>end;<br>这是从delphi的FileCtrl.pas中取出来的.
 
多人接受答案了。
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部