Solved

Borland C++ Builder control accept dropped files

Posted on 2001-08-22
6
1,121 Views
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.
0
Comment
Question by:lirtua
  • 3
  • 3
6 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
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.
Example:

class TForm1 : public TForm
{
private:
void virtual __fastcall WMDropFiles(TWMDropFiles &message);
public:
__fastcall TForm1(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES,TWMDropFiles,WMDropFiles);
END_MESSAGE_MAP (TForm);
};

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

void __fastcall TForm1::WMDropFiles (TWMDropFiles &message)
{
...
}
0
 

Author Comment

by:lirtua
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?
0
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 6417339
>>How do I get the filename & path?

void __fastcall TForm1::WMDropFiles (TWMDropFiles &message)
 
{
 UINT FileCount = DragQueryFile((HDROP) Msg.Drop, 0xFFFFFFFF, NULL,
 0);
 AnsiString FileName;
 AnsiString FileExtension;
 
 int FileLength;
 for(UINT ii=0; ii < FileCount; ii++)
 {
   FileName.SetLength(MAX_PATH);
 FileLength = DragQueryFile((HDROP)Msg.Drop, ii,
 FileName.c_str(), FileName.Length());
 FileName.SetLength(FileLength);
 ProcessFile(FileLength) // <------ Whatever you want it to be...
 } // end for
 DragFinish((HDROP) Msg.Drop);
 }
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:lirtua
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.
0
 
LVL 14

Accepted Solution

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

Author Comment

by:lirtua
ID: 6423024
Fantastic Alex - thanks for the help!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now