home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue52 / Clinic / ComputerNameSelectorForm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-10-21  |  1.3 KB  |  63 lines

  1. unit ComputerNameSelectorForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     procedure Button1Click(Sender: TObject);
  13.   private
  14.     { Private declarations }
  15.   public
  16.     { Public declarations }
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.DFM}
  25.  
  26. uses
  27.   ShlObj;
  28.  
  29. function GetComputerName: String;
  30. var
  31.   BrowseInfo: TBrowseInfo;
  32.   ItemIDList: PItemIDList;
  33.   ComputerName: array[0..MAX_PATH] of Char;
  34.   WindowList: Pointer;
  35.   Success: Boolean;
  36. begin
  37.   if Failed(SHGetSpecialFolderLocation(Application.Handle, CSIDL_NETWORK, ItemIDList)) then
  38.     raise Exception.Create('Computer Name Dialog Not Supported');
  39.   FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
  40.   BrowseInfo.hwndOwner := Application.Handle;
  41.   BrowseInfo.pidlRoot := ItemIDList;
  42.   BrowseInfo.pszDisplayName := ComputerName;
  43.   BrowseInfo.lpszTitle := 'Select Remote Machine';
  44.   BrowseInfo.ulFlags := BIF_BROWSEFORCOMPUTER;
  45.   WindowList := DisableTaskWindows(0);
  46.   try
  47.     Success := SHBrowseForFolder(BrowseInfo) <> nil;
  48.   finally
  49.     EnableTaskWindows(WindowList);
  50.   end;
  51.   if Success then
  52.     Result := ComputerName
  53.   else
  54.     Result := ''
  55. end;
  56.  
  57. procedure TForm1.Button1Click(Sender: TObject);
  58. begin
  59.   ShowMessage(GetComputerName)
  60. end;
  61.  
  62. end.
  63.