VCL Delphi

Title: An Descendant from TTreView which shows the hierarchy of LAN
Question: The component shows you LAN resources which are represented
as a tree.
How to use ?
Set Component on Form and assign property Active in True
Enjoy !
Answer:
unit mmLanTreeView;
interface
uses
Windows,Messages,SysUtils, Classes, Controls, ComCtrls;
type
TmmLanTreeView = class(TCustomTreeView)
private
FActive: Boolean;
FOnProgress: TNotifyEvent;
FOnEndScan: TNotifyEvent;
procedure SetActive(const Value: Boolean);
procedure SetOnProgress(const Value: TNotifyEvent);
procedure SetOnEndScan(const Value: TNotifyEvent);
{ Private declarations }
protected
procedure LoadLevel(aRoot:pointer;aRootTree:TTreeNode);
{ Protected declarations }
public
property Items;
procedure RefreshTree;
{ Public declarations }
published
property OnProgress:TNotifyEvent read FOnProgress write SetOnProgress;
property Active:Boolean read FActive write SetActive;
property OnEndScan:TNotifyEvent read FOnEndScan write SetOnEndScan;
property Align;
property Anchors;
property AutoExpand;
property BevelEdges;
property BevelInner;
property BevelOuter;
property BevelKind default bkNone;
property BevelWidth;
property BiDiMode;
property BorderStyle;
property BorderWidth;
property ChangeDelay;
property Color;
property Ctl3D;
property Constraints;
property DragKind;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property HideSelection;
property HotTrack;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('mmVCL', [TmmLanTreeView]);
end;
{ TmmLanTreeView }
procedure TmmLanTreeView.LoadLevel(ARoot: Pointer; ARootTree: TTreeNode);
var
Buffer: array [1..512] of TNetResource;
hEnum,Count,BufSize:Cardinal;
s:String;
vNode:TTreeNode;
i:integer;
R:TNetResource;
vData:^TNetResource;
begin
Count:=512;
BufSize:=SizeOf(TNetResource)*512;
if WNetOpenEnumA(RESOURCE_GLOBALNET,RESOURCETYPE_ANY,0,aRoot,HEnum)=NO_ERROR then
begin
while WNetEnumResourceA(HEnum,Count,@Buffer,BufSize)=NO_ERROR do
for i:=1 to Count do
begin
s:=String(Buffer[i].lpRemoteName);
if s='' then break;
vNode:=Items.AddChild(aRootTree,s);
if Assigned(FOnProgress) then FOnProgress(Self);
if not Active then Exit;
with vNode do begin
New(vData);
vData^:=Buffer[i];
Data:=vData;
if (Buffer[i].dwUsage=RESOURCEUSAGE_CONTAINER) or (Buffer[i].dwUsageRESOURCEUSAGE_RESERVED) then
begin
r:=Buffer[i];
LoadLevel(@r,vNode);
end;
end;
end;
WNetCloseEnum(hEnum);
end;
//if Items.Count15 then exit;
end;
procedure TmmLanTreeView.RefreshTree;
begin
LoadLevel(nil,nil);
if Assigned( FOnEndScan) then FOnEndScan(Self);
end;
procedure TmmLanTreeView.SetActive(const Value: Boolean);
begin
FActive := Value;
if Value then RefreshTree else
Items.Clear;
end;
procedure TmmLanTreeView.SetOnEndScan(const Value: TNotifyEvent);
begin
FOnEndScan := Value;
end;
procedure TmmLanTreeView.SetOnProgress(const Value: TNotifyEvent);
begin
FOnProgress := Value;
end;
end.