Ir al contenido


Foto

[TRUCO DELPHI] Seleccionar Ordenador.


  • Por favor identifícate para responder
No hay respuestas en este tema

#1 sir.dev.a.lot

sir.dev.a.lot

    Advanced Member

  • Miembros
  • PipPipPip
  • 545 mensajes
  • Location127.0.0.1

Escrito 10 diciembre 2016 - 04:17

[TRUCO DELPHI] Seleccionar Ordenador.


delphi
  1. Uses
  2. ActiveX,
  3. ShlObj,
  4. Windows;
  5.  
  6. function SelectComputer(Const Caption: String; out Computer: String): Boolean;
  7. Var
  8. BrowseInfo : TBrowseInfo;
  9. ShellMalloc : IMalloc;
  10. RootItemIDList: PItemIDList;
  11. ItemIDList : PItemIDList;
  12. Buffer : PChar;
  13. begin
  14. Result := False;
  15. Computer := '';
  16. FillChar(BrowseInfo, SizeOf(BrowseInfo), 0);
  17. If (ShGetMalloc(ShellMalloc) = S_OK) And
  18. (ShellMalloc <> Nil) Then
  19. begin
  20. Buffer := ShellMalloc.Alloc(MAX_COMPUTERNAME_LENGTH + 1);
  21. try
  22. SHGetSpecialFolderLocation(0, CSIDL_NETWORK, RootItemIDList);
  23. With BrowseInfo Do
  24. begin
  25. hwndOwner := Application.Handle;
  26. pidlRoot := RootItemIDList;
  27. pszDisplayName := Buffer;
  28. lpszTitle := PChar(Caption);
  29. ulFlags := BIF_BROWSEFORCOMPUTER;
  30. end;
  31. ItemIDList := ShBrowseForFolder(BrowseInfo);
  32. Result := (ItemIDList <> Nil);
  33. If Result Then
  34. begin
  35. ShellMalloc.Free(ItemIDList);
  36. Computer := AnsiUpperCase(Buffer);
  37. end;
  38. finally
  39. ShellMalloc.Free(RootItemIDList);
  40. ShellMalloc.Free(Buffer);
  41. end;
  42. end;
  43. end;

Saludos!


  • 1