Borland C++ Builder control accept dropped files

Borland C++ Builder control accept dropped files

Q:  How do you make a control accept a file which is dragged over it?
Example:   *.txt file is dropped onto an application and the file is opened by the application.

I would like to have an edit box accept a *.txt file which is dropped onto it.  In addition, I would like an image box accept a *.bmp file which is dropped onto it.

I do not need help with opening these file types.  What I need is how to have the control recognize that a file is being dropped, and how do I get the filename, path, etc.
Who is Participating?
AlexVirochovskyConnect With a Mentor Commented:
Sorry, I forget one think(very impotant)
void __fastcall TForm1::FormCreate(TObject *Sender)
  DragAcceptFiles(Form1-> Handle, true);
To deal file dropping
on a form, you have to do the following:

1) in the header file of the form, initialize the handling of the
WM_DROPFILES message, specifying the handling funtion.

class TForm1 : public TForm
void virtual __fastcall WMDropFiles(TWMDropFiles &message);
__fastcall TForm1(TComponent* Owner);

2) in your source code insert the function which should handle the
file dropping. Example:

void __fastcall TForm1::WMDropFiles (TWMDropFiles &message)
lirtuaAuthor Commented:
The code you supplied compiles and the application runs.  However, when dragging a file over the application, the nodrop icon is displayed.

Also, I cannot find information about the struct TWMDropFiles although I see its definition in messages.hpp.

How do I get the filename & path?
The new generation of project management tools

With’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

>>How do I get the filename & path?

void __fastcall TForm1::WMDropFiles (TWMDropFiles &message)
 UINT FileCount = DragQueryFile((HDROP) Msg.Drop, 0xFFFFFFFF, NULL,
 AnsiString FileName;
 AnsiString FileExtension;
 int FileLength;
 for(UINT ii=0; ii < FileCount; ii++)
 FileLength = DragQueryFile((HDROP)Msg.Drop, ii,
 FileName.c_str(), FileName.Length());
 ProcessFile(FileLength) // <------ Whatever you want it to be...
 } // end for
 DragFinish((HDROP) Msg.Drop);
lirtuaAuthor Commented:
Thank you for the information on this.  The code you have supplied is compiling without error.  I appreciate that.

I think were getting close.  However, the form still will not accept a dropped file.  When dragging a file over the form during runtime, the nodrop icon is displayed.

With this final detail, i believe all will be well in the file dropping realm.
lirtuaAuthor Commented:
Fantastic Alex - thanks for the help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.