Default
Google

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.
 
 1.
  Start a new project using File | New Application.
 
 2.
  Add a ListBox.
 
 3.
  Edit the OnCreate event of your form:
 
void __fastcall TForm1::FormCreate(TObject *Sender)
{
    DragAcceptFiles(ListBox1->Handle, true);
}
 
 4.
  Open your header file:
 
private:
    MESSAGE void __fastcall Drop(TWMDropFiles &);
    BEGIN_MESSAGE_MAP
        MESSAGE_HANDLER(WM_DROPFILES, TWMDropFiles, Drop);
    END_MESSAGE_MAP(TForm);
 
 5.
  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



Acquiring image from ProHosting Banner Exchange