uses
uProcessMemMgr;
function TForm1.GrabTreeView(TreeView: TTreeView; extWnd: HWND): Integer;
const
MaxTextSize = 1024;
var
TreeWnd: HWND;
MM: TProcessMemMgr;
CurrentItem: HTREEITEM;
TVItem: TTVItem;
PrTVItem: PTVItem;
PrText: PChar;
procedure AddNodes(TreeView: TTreeView; hTree: HWND; ASrc: HTREEITEM; ADst: TTreeNode);
var
NextDst: TTreeNode;
NextSrc: HTREEITEM;
begin
if not Assigned(ASrc)
then
Exit;
TVItem.hItem := ASrc;
TVItem.mask := TVIF_TEXT
or TVIF_IMAGE
or TVIF_PARAM;
MM.
Write(TVItem, PrTVItem, SizeOf(TTVItem));
{Get Next TreeView Item}
TreeView_GetItem(TreeWnd, PrTVItem^);
{Add to our TreeView }
NextDst := TreeView.Items.AddChild(ADst, MM.ReadStr(PrText));
{Get Next TreeView Item}
NextSrc := TreeView_GetChild(hTree, ASrc);
while Assigned(NextSrc)
do
begin
AddNodes(TreeView, hTree, NextSrc, NextDst);
NextSrc := TreeView_GetNextItem(hTree, NextSrc, TVGN_NEXT);
end;
end;
begin
TreeWnd := extWnd;
if TreeWnd = 0
then
raise Exception.Create('
Handle not found...');
try
MM := CreateProcessMemMgrForWnd(TreeWnd);
PrTVItem := MM.AllocMem(SizeOf(TTVItem));
PrText := MM.AllocMem(MaxTextSize);
TVItem.mask := TVIF_TEXT;
TVItem.pszText := PrText;
TVItem.cchTextMax := MaxTextSize;
CurrentItem := TreeView_GetRoot(TreeWnd);
repeat
AddNodes(TreeView, TreeWnd, CurrentItem,
nil);
CurrentItem := TreeView_GetNextItem(TreeWnd, CurrentItem, TVGN_NEXT);
until CurrentItem =
nil;
finally
MM.Free;
end;
if TreeView.Items.Count > 0
then
TreeView.Items[0].Expand(Boolean(True));
Result := TreeView_GetVisibleCount(extWnd);
end;