How can I drop files in my ListBox?
Applies To: C++Builder 1 or higher
Category: Knowledge Base
- I have to create an application that allows the user to drop files in my ListBox.
-
- Start a new project using File | New Application.
-
- Add a ListBox.
-
- Edit the OnCreate event of your form:
-
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- DragAcceptFiles(ListBox1->Handle, true);
- }
-
- Open your header file:
-
- private:
- MESSAGE void __fastcall Drop(TWMDropFiles &);
- BEGIN_MESSAGE_MAP
- MESSAGE_HANDLER(WM_DROPFILES, TWMDropFiles, Drop);
- END_MESSAGE_MAP(TForm);
-
- Insert in your source code:
-
- void __fastcall TForm1::Drop(TWMDropFiles &message)
- {
- int count = DragQueryFile((HDROP)message.Drop, 0xFFFFFFFFF,
- NULL, 0);
- for(int x = 0; x < count; x++)< count; x++)
- {
- char name[MAX_PATH];
- DragQueryFile((HDROP)message.Drop, x, name, sizeof(name));
- ListBox1->Items->Add(name);
- }
- DragFinish((HDROP)message.Drop);
- }
C++Builder Developer's Network
Copyright © Yoto Yotov