whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

44 Visitors Online


 
...select a computer from the network neighborhood?
Autor: Sergey Dolinin
[ Print tip ]  

Tip Rating (9):  
     


uses
  
ShlObj, ActiveX;

function BrowseComputer(DialogTitle: stringvar CompName: string;
  bNewStyle: Boolean): Boolean;
  // bNewStyle: If True, this code will try to use the "new"
  // BrowseForFolders UI on Windows 2000/XP
const
  
BIF_USENEWUI = 28;
var
  
BrowseInfo: TBrowseInfo;
  ItemIDList: PItemIDList;
  ComputerName: array[0..MAX_PATH] of Char;
  Title: string;
  WindowList: Pointer;
  ShellMalloc: IMalloc;
begin
  if 
Failed(SHGetSpecialFolderLocation(Application.Handle, CSIDL_NETWORK, ItemIDList)) then
    raise 
Exception.Create('Unable open browse computer dialog');
  try
    
FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
    BrowseInfo.hwndOwner := Application.Handle;
    BrowseInfo.pidlRoot := ItemIDList;
    BrowseInfo.pszDisplayName := ComputerName;
    Title := DialogTitle;
    BrowseInfo.lpszTitle := PChar(Pointer(Title));
    if bNewStyle then
      
BrowseInfo.ulFlags := BIF_BROWSEFORCOMPUTER or BIF_USENEWUI
    else
      
BrowseInfo.ulFlags := BIF_BROWSEFORCOMPUTER;
    WindowList := DisableTaskWindows(0);
    try
      
Result := SHBrowseForFolder(BrowseInfo) <> nil;
    finally
      
EnableTaskWindows(WindowList);
    end;
    if Result then CompName := ComputerName;
  finally
    if 
Succeeded(SHGetMalloc(ShellMalloc)) then
      
ShellMalloc.Free(ItemIDList);
  end;
end;

// Example

procedure TForm1.Button1Click(Sender: TObject);
var
  
Computer: string;
begin
  
BrowseComputer('...', Computer, True);
  label1.Caption := Computer;
end;

 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners