Title: Browse for computer
Question: How to pop a dialog box where you can choose a
computer on the network neighborhood ?
Answer:
{** Compile fine with D3, Should be OK with other version **}
function BrowseForComputer(const winhandle : THANDLE; const title : string) : string;
WinHandle : window handle (Form1.Handle) or 0.
Title : title of the dialog box
result : selected computer, or emptystring if Cancel.
Based on some code find in newsgroup.
uses
shlobj;
{...}
function BrowseForComputer(const winhandle : THANDLE; const title : string) : string;
//Pop up the standard 'Browse for computer' dialog box
var
BrowseInfo: TBrowseInfo;
IDRoot: PItemIDList;
Path: array[0..MAX_PATH] of Char;
begin
// Get the Item ID for Network Neighborhood
SHGetSpecialFolderLocation(winHandle, CSIDL_NETWORK, IDRoot);
ZeroMemory(@BrowseInfo, SizeOf(TBrowseInfo));
ZeroMemory(@path, MAX_PATH);
BrowseInfo.hwndOwner := winhandle;
BrowseInfo.pidlRoot := IDRoot;
BrowseInfo.lpszTitle := PChar(title);
BrowseInfo.pszDisplayName := @path;
// Include this flag to show computer only
BrowseInfo.ulFlags := BIF_BROWSEFORCOMPUTER;// or BIF_RETURNONLYFSDIRS ;
// Show the browse dialog, get the Item ID for the selected item and convert it to a path
SHBrowseForFolder(BrowseInfo);
// SHGetPathFromIDList(IDList, Path);
result := path;
end;