📄 searchgroupthreadunit.pas
字号:
unit SearchGroupThreadUnit;
interface
uses Windows, Messages, SysUtils, Classes,ComCtrls,Dialogs;
type
TSearchGroupThread=class(TThread)
private
MyHost : string;
TemNode : TTreeNode; //TemNode is the temp node
public
MyGroup : string;
MyTree : TTreeView;
MyNode : TTreeNode;
Terminated : boolean;
protected
procedure Execute; override;
Procedure AddHost;
procedure notfind;
procedure GroupProgress;
end;
implementation
uses main,SearchHostThreadUnit;
procedure TSearchGroupThread.AddHost;
var
MyItemPtr : PMyTreeItem;
begin
with MainForm do
begin
//listbox1.Items.Add(myhost);
//listbox1.TopIndex := listbox1.Items.Count -1;
Statusbar.Panels[1].Text := '正在搜索:'+MyHost;
New(MyItemPtr);
MyItemPtr^.DirName :=MyHost;
MyItemPtr^.Group :=MyGroup;
TemNode:=MyTree.Items.AddChild(MyNode,myhost); //MyNode is group
TemNode.Data := MyItemPtr; // TemNode is host
MyNode.ImageIndex :=9;
MyNode.SelectedIndex :=9;
TemNode.ImageIndex := 12;
TemNode.SelectedIndex :=9;
MyNode.expand(false);
end;
end;
procedure TSearchGroupThread.notfind;
begin
MyNode.ImageIndex :=14;
MyNode.SelectedIndex :=14;
end;
procedure TSearchGroupThread.GroupProgress;
begin
with MainForm do
begin
inc(FinishNum);
statusbar.Panels[3].Text :='共'+inttostr(groupnum)+
'个工作组,已搜索了'+inttostr(FinishNum)+'个';
end;
end;
procedure TSearchGroupThread.Execute;
Var
EnumHandle : THandle;
WorkgroupRS : TNetResource;
Buf : Array[1..500] of TNetResource;
BufSize : DWord;
Entries : DWord;
Result : Integer;
searcher : TSearchHostThread;
EverFound : boolean;
begin
Terminated:=false;
if stop then exit;
if terminated then exit;
EverFound:=false;
MyGroup := MyGroup + #0;
FillChar(WorkgroupRS, SizeOf(WorkgroupRS) , 0);
With WorkgroupRS do begin
dwScope := 2;
dwType := 3;
dwDisplayType := 1;
dwUsage := 2;
lpRemoteName := @MyGroup[1];
end;
Result:=WNetOpenEnum( RESOURCE_GLOBALNET,
RESOURCETYPE_ANY,
0,
@WorkgroupRS,
EnumHandle );
if Result= NO_ERROR then
Repeat
Entries := 1;
BufSize := SizeOf(Buf);
Result := WNetEnumResource( EnumHandle,Entries,@Buf,BufSize );
If (Result = NO_ERROR) and (Entries = 1) then begin
myhost:= StrPas(Buf[1].lpRemoteName);
Synchronize(AddHost);
everFound:=true;
//dir
if stop then exit;
if terminated then exit;
searcher:=TSearchHostThread.create(true);
searcher.MyTree := MyTree;
searcher.MyNode := TemNode;
searcher.MyHost := MyHost;
searcher.MyGroup := MyGroup;
searcher.FreeOnTerminate := true;
searcher.Resume;
searcher.WaitFor;
//dir
end;
//if stop then exit;
if terminated then exit;
Until (Entries <> 1) or (Result <> NO_ERROR);
WNetCloseEnum( EnumHandle );
if (not everFound) then Synchronize(NotFind);
Synchronize(GroupProgress);
//if ver>4 then if terminated then exit;
Terminated:=true;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -