Procedure TForm1.CopyFilenames1Click(Sender: TObject);
Procedure IncL(
Var L, Le: Integer; VTRec: PVTRec);
Var i, i2: Integer;
Begin
i := FileList2[VTRec^.
Index].Files[VTRec^.FileIndex].Directory;
While i >= 0
{i > dpIsRootDir} do Begin
i2 := Length(Directories[i].DirName);
Inc(L, i2);
Inc(Le, i2);
i := Directories[i].Parent;
End;
i2 := Length(FileList2[VTRec^.
Index].Files[VTRec^.FileIndex].FileName);
Inc(L, i2 + 2);
Inc(Le, i2 + 1);
End;
Procedure AddP(
Var PW,
PE: PWideChar;
Var PA: PAnsiChar; VTRec: PVTRec);
Var i, i2: Integer;
X:
Array[0..255]
of Integer;
W: PWideChar;
S:
String;
Begin
i2 := 0;
i := FileList2[VTRec^.
Index].Files[VTRec^.FileIndex].Directory;
While i >= 0
{i > dpIsRootDir} do Begin
X[i2] := i; Inc(i2);
i := Directories[i].Parent;
End;
While i2 > 0
do Begin
Dec(i2);
i := Length(Directories[X[i2]].DirName);
W := PWideChar(Directories[X[i2]].DirName);
S := W;
If PW <>
nil Then Begin MoveMemory(PW, W, i * 2); Inc(PW, i);
End;
If PE <>
nil Then Begin MoveMemory(
PE, W, i * 2); Inc(
PE, i);
End;
If PA <>
nil Then Begin MoveMemory(PA, Pointer(S), i); Inc(PA, i);
End;
End;
i := Length(FileList2[VTRec^.
Index].Files[VTRec^.FileIndex].FileName);
W := PWideChar(FileList2[VTRec^.
Index].Files[VTRec^.FileIndex].FileName);
S := W;
If PW <>
nil Then Begin MoveMemory(PW, W, i * 2); Inc(PW, i); PW^ := #13; Inc(PW); PW^ := #10; Inc(PW);
End;
If PE <>
nil Then Begin MoveMemory(
PE, W, i * 2); Inc(
PE, i);
PE^ := #0; Inc(
PE);
End;
If PA <>
nil Then Begin MoveMemory(PA, Pointer(S), i); Inc(PA, i); PA^ := #13; Inc(PA); PA^ := #10; Inc(PA);
End;
End;
Var L, Le: Integer;
Node, Child: PVirtualNode;
PW, PE1: PWideChar;
PE2: PInteger;
PA: PAnsiChar;
Begin
EnableControls(ecProcessX);
L := 0;
Le := 0;
Node := VirtualStringTree1.GetFirst;
While Node <>
nil do
If vsSelected
in Node^.States
Then Begin
If Node^.Parent = VirtualStringTree1.RootNode
Then Begin
Child := Node^.FirstChild;
While Child <>
nil do Begin
IncL(L, Le, PVTRec(VirtualStringTree1.GetNodeData(Child)));
Child := Child^.NextSibling;
End;
Node := Node^.NextSibling;
End Else Begin
IncL(L, Le, PVTRec(VirtualStringTree1.GetNodeData(Node)));
Node := VirtualStringTree1.GetNext(Node);
End;
Inc(L, 2);
End Else Node := VirtualStringTree1.GetNext(Node);
Inc(L);
Inc(Le);
If (Le <= 2)
or not OpenClipboard(
Handle)
Then Exit;
EmptyClipboard;
//GlobalFree(ClipboardA);
GlobalFree(ClipboardE2);
//GlobalFree(ClipboardE1);
//GlobalFree(ClipboardW);
ClipboardW := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE, L * 2);
ClipboardE1 := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE, SizeOf(TDropFiles) + Le * 2);
ClipboardE2 := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE, 4);
ClipboardA := GlobalAlloc(GMEM_MOVEABLE + GMEM_DDESHARE, L);
PW := GlobalLock(ClipboardW);
PE1 := GlobalLock(ClipboardE1);
PE2 := GlobalLock(ClipboardE2);
PA := GlobalLock(ClipboardA);
If PE2 <>
nil Then PInteger(PE2)^ := DROPEFFECT_COPY
or DROPEFFECT_LINK;
If PE1 <>
nil Then Begin
ZeroMemory(PE1, SizeOf(TDropFiles));
PDropFiles(PE1)^.pFiles := SizeOf(TDropFiles);
PDropFiles(PE1)^.fWide := True;
Inc(Integer(PE1), SizeOf(TDropFiles));
End;
Node := VirtualStringTree1.GetFirst;
While Node <>
nil do
If vsSelected
in Node^.States
Then Begin
If Node^.Parent = VirtualStringTree1.RootNode
Then Begin
Child := Node^.FirstChild;
While Child <>
nil do Begin
AddP(PW, PE1, PA, PVTRec(VirtualStringTree1.GetNodeData(Child)));
Child := Child^.NextSibling;
End;
Node := Node^.NextSibling;
End Else Begin
AddP(PW, PE1, PA, PVTRec(VirtualStringTree1.GetNodeData(Node)));
Node := VirtualStringTree1.GetNext(Node);
End;
If PW <>
nil Then Begin PW^ := #13; Inc(PW); PW^ := #10; Inc(PW);
End;
If PA <>
nil Then Begin PA^ := #13; Inc(PA); PA^ := #10; Inc(PA);
End;
End Else Node := VirtualStringTree1.GetNext(Node);
If PW <>
nil Then PW^ := #0;
If PA <>
nil Then PA^ := #0;
If PE1 <>
nil Then PE1^ := #0;
GlobalUnlock(ClipboardA);
GlobalUnlock(ClipboardE2);
GlobalUnlock(ClipboardE1);
GlobalUnlock(ClipboardW);
If PW <>
nil Then SetClipboardData(CF_UNICODETEXT, ClipboardW);
If PA <>
nil Then SetClipboardData(CF_TEXT, ClipboardA);
If PE1 <>
nil Then SetClipboardData(CF_HDROP, ClipboardE1);
If PE2 <>
nil Then SetClipboardData(RegisterClipboardFormat(CFSTR_PREFERREDDROPEFFECT), ClipboardE2);
CloseClipboard;
EnableControls(ecAll);
End;