//---------------------------------------------------------------------------
//in
source...
__fastcall TForm1::TForm1(TComponent*
Owner)
: TForm(Owner)
{
//turn
on file d&d for the TreeView
DragAcceptFiles(TreeView1->Handle,
true);
//save
the old window procedure
OldTreeViewWP
= TreeView1->WindowProc;
//assign
a new window procedure
TreeView1->WindowProc
= NewTreeViewWP;
}
//---------------------------------------------------------------------------
//new
TreeView window procedure
void __fastcall
TForm1::NewTreeViewWP(TMessage &Msg)
{
if
(Msg.Msg == WM_DROPFILES)
{
//find the point and node of the drop
POINT P;
DragQueryPoint((HDROP)Msg.WParam, &P);
TTreeNode *DropNode = TreeView1->GetNodeAt(P.x, P.y);
//find the number of files dropped
int num_files = DragQueryFile((HDROP)Msg.WParam, 0xFFFFFFFF,
(LPSTR)NULL, NULL);
TreeView1->Items->BeginUpdate();
for (int
index = 0; index < num_files; index++)
{
//find the length of the filename
int NameLength = DragQueryFile((HDROP)Msg.WParam, index,
NULL, NULL);
char *FileName = new char[NameLength];
//get the filename
DragQueryFile((HDROP)Msg.WParam, index, FileName, NameLength);
//add it to the TreeView
TreeView1->Items->Add(DropNode, FileName);
delete [] FileName;
}
TreeView1->Items->EndUpdate();
DragFinish((HDROP)Msg.WParam);
Msg.Result = 0;
}
OldTreeViewWP(Msg);
}
//---------------------------------------------------------------------------
void __fastcall
TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
//restore
the original window procedure
TreeView1->WindowProc
= OldTreeViewWP;
//turn
off file d&d for the TreeView
DragAcceptFiles(TreeView1->Handle,
false);
}
|