Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Borland C++ Builder control accept dropped files

Posted on 2001-08-22
Medium Priority
Last Modified: 2007-12-19
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.
Question by:lirtua
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
LVL 14

Expert Comment

ID: 6414848
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)

Author Comment

ID: 6415030
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?
LVL 14

Expert Comment

ID: 6417339
>>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);
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.


Author Comment

ID: 6419434
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.
LVL 14

Accepted Solution

AlexVirochovsky earned 200 total points
ID: 6421357
Sorry, I forget one think(very impotant)
void __fastcall TForm1::FormCreate(TObject *Sender)
  DragAcceptFiles(Form1-> Handle, true);

Author Comment

ID: 6423024
Fantastic Alex - thanks for the help!

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question