Drag & Drop Files
How to enabled drag&drop from explorer to your window and retrieve a list of dropped files?
1. Enable your window (Form) to accept dropped files (DragAcceptFiles )
2. Add a message handler for WM_DROPFILES
3. Use DragQueryFile ( on WM_DROPFILES) to get the dropped files count and their full path.
C++:
-
//---------------------------------------------------------------------------
-
void __fastcall TForm1::FormCreate(TObject *Sender)
-
{
-
//enable drag&drop files
-
DragAcceptFiles(this->Handle,true);
-
}
-
//---------------------------------------------------------------------------
C++:
-
class TForm1 : public TForm
-
{
-
__published: // IDE-managed Components
-
-
void __fastcall FormCreate(TObject *Sender);
-
-
private: // User declarations
-
-
void __fastcall WMDropFile(TWMDropFiles &Msg);
-
-
public: // User declarations
-
-
__fastcall TForm1(TComponent* Owner);
-
-
BEGIN_MESSAGE_MAP
-
//add message handler for WM_DROPFILES
-
VCL_MESSAGE_HANDLER(WM_DROPFILES, TWMDropFiles, WMDropFile)
-
END_MESSAGE_MAP(TComponent)
-
-
};
C++:
-
//---------------------------------------------------------------------------
-
void __fastcall TForm1::WMDropFile(TWMDropFiles &Msg)
-
{
-
char filePath[MAX_PATH];
-
TStringList *FilesDroped=new TStringList();
-
-
//get dropped files count
-
int cnt=::DragQueryFile((HDROP)Msg.Drop,0xFFFFFFFF,NULL,0);
-
-
//get dropped files path
-
for(int i=0;i<cnt;i++)
-
{
-
::DragQueryFile((HDROP)Msg.Drop, i,filePath,MAX_PATH);
-
FilesDroped->Add(filePath);
-
}
-
-
ShowMessage(FilesDroped->Text);
-
-
delete FilesDroped;
-
}

related things:
Author: Raz | On February 10th, 2007 | C++ Builder, [ En ] | No Comments
Q: So what can I do next?
A: You can Buy me a Beer or Coffee. You can say Hi! or peek on the related stuff. You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.
Spammers: Beware of » my Dog! «




