請問各位前輩有關Drag&Drop的問題
我建立兩個ListView,ListView1 和 ListView2, ListView1顯示目錄底下所有檔案. 我想要從ListView1拉檔案到ListView2要如何才能把檔案拉過去謝謝 底下是我的程式碼請各位前輩幫我
//---------------------------------------------------------------------------
//Unit1.cpp
#include
#pragma hdrstop #include "Unit1.h"
#define TreeViewSelectedFullPath GetFullPath("",TreeView->Selected)
#define ListViewSelectedFullPath GetFullPath(ListView->Selected->Caption,TreeView->Selected)
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//#pragma message("test")
TPicViewForm *PicViewForm;
//---------------------------------------------------------------------------
__fastcall TPicViewForm::TPicViewForm(TComponent* Owner)
: TForm(Owner)
{
bCloseForm = false;
Application->OnException = AppException;
}
//---------------------------------------------------------------------------
void __fastcall TPicViewForm::AppException(TObject *Sender,
Exception *E)
{
if(E->Message.Pos("I/O error 21"))
{
ShowMessage("Device " AnsiString(DriveComboBox1->Drive) " is not ready !");
DriveComboBox1->Drive = DirectoryListBox1->Drive;
}
}
//---------------------------------------------------------------------------
void __fastcall TPicViewForm::DirectoryListBox1Change(TObject *Sender)
{
TListItem *ListItem;
TSearchRec sr;
TRect DRect,SRect;
String AppDir=ExtractFileDir(Application->ExeName);
//int iPicCount=0;
int i; ImageList1->Clear();
ListView1->Items->Clear(); if(DirectoryListBox1->Directory.LastDelimiter("\\") == DirectoryListBox1->Directory.Length())
DirectoryListBox1->Directory.SetLength(DirectoryListBox1->Directory.Length()-1); if(!FindFirst(DirectoryListBox1->Directory "\\*.mp3", faAnyFile, sr))
{
do
{
ListItem = ListView1->Items->Add();
ListItem->Caption = sr.Name;
} while(FindNext(sr) == 0);
}
} //---------------------------------------------------------------------------
void __fastcall TPicViewForm::FormCloseQuery(TObject *Sender,
bool &CanClose)
{
bCloseForm = true;
} //---------------------------------------------------------------------------
void __fastcall TPicViewForm::ListView2DragOver(TObject *Sender,
TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
/* if(dynamic_cast (Source))
Accept = true;*/
}
//--------------------------------------------------------------------------- void __fastcall TPicViewForm::ListView1MouesDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
TListItem *ListItem;
TSearchRec sr; ListView1->Selected = ListView1->GetItemAt(X,Y);
if (ListView1->GetItemAt(X,Y) != NULL )
{
Application->MessageBox("This should be on top.", "Look", MB_OK); //THitTests MyHitTest = ListView1->GetHitTestInfoAt(X,Y); ListItem = ListView2->Items->Add();
ListItem->Caption = sr.Name;
} }
//--------------------------------------------------------------------------- //---------------------------------------------------------------------------
//unit1.h
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include
#include
#include
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
class TPicViewForm : public TForm
{
__published: // IDE-managed Components
TStatusBar *StatusBar1;
TPanel *Panel2;
TPanel *Panel3;
TDriveComboBox *DriveComboBox1;
TDirectoryListBox *DirectoryListBox1;
TImageList *ImageList1;
TListView *ListView1;
TListView *ListView2;
void __fastcall DirectoryListBox1Change(TObject *Sender);
void __fastcall FormCloseQuery(TObject *Sender, bool &CanClose);
void __fastcall ListView2DragOver(TObject *Sender, TObject *Source,
int X, int Y, TDragState State, bool &Accept);
void __fastcall ListView1MouesDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y);
private: // User declarations
bool bCloseForm;
void __fastcall AppException(TObject *Sender,Exception *E);
public: // User declarations
__fastcall TPicViewForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TPicViewForm *PicViewForm;
//---------------------------------------------------------------------------
#endif