uses shlobj,ActiveX;//注意,一定要use这两个!!!!<br>//函数功能:获取网上邻居目录<br>//参数: caption-对话框标题,Directory,选择的目录,Result:是否有选择;<br>//author:雪鹰<br>function SelectNetDir(const Caption: string;<br> out Directory: string): Boolean;<br>var<br> WindowList: Pointer;<br> BrowseInfo: TBrowseInfo;<br> Buffer: PChar;<br> RootItemIDList, ItemIDList: PItemIDList;<br> ShellMalloc: IMalloc;<br> IDesktopFolder: IShellFolder;<br> Eaten, Flags: LongWord;<br>begin<br> Result := False;<br> Directory := '';<br> FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);<br> if (ShGetMalloc(ShellMalloc) = S_OK) and (ShellMalloc <> nil) then<br> begin<br> Buffer := ShellMalloc.Alloc(MAX_PATH);<br> try<br> RootItemIDList := nil;<br> SHGetSpecialFolderLocation(Application.handle,CSIDL_NETWORK,RootItemIDList);<br> with BrowseInfo do<br> begin<br> hwndOwner := Application.Handle;<br> pidlRoot := RootItemIDList;<br> pszDisplayName := Buffer;<br> lpszTitle := PChar(Caption);<br> ulFlags := BIF_RETURNONLYFSDIRS;<br> end;<br> WindowList := DisableTaskWindows(0);<br> try<br> ItemIDList := ShBrowseForFolder(BrowseInfo);<br> finally<br> EnableTaskWindows(WindowList);<br> end;<br> Result := ItemIDList <> nil;<br> if Result then<br> begin<br> ShGetPathFromIDList(ItemIDList, Buffer);<br> ShellMalloc.Free(ItemIDList);<br> Directory := Buffer;<br> end;<br> finally<br> ShellMalloc.Free(Buffer);<br> end;<br> end;<br>end;<br><br><br>example:<br> if selectNetDir('test',od) then<br> showmessage(od)<br>