Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Drag and drop a file from Explorer

6 views
Skip to first unread message

Nate Lockwood

unread,
Jul 18, 2005, 11:43:27 AM7/18/05
to
1. My supervisor wants me to modify an application so that he can drag
and drop a data file from Explorer on it and have it open and process
the file automatically.

This requires that I provide object names: sender class name and object
class names. What would they be in this case?

2. Would this work if the application is minimized to the task bar? I
don't want the application to take up much screen real estate when it's
being run this way. Should I build a second controlling application
that can start my main AP minimized if it's not running and pass the
file name?

My main AP is in Builder 5 and it is to run on NT4 or XP.

TIA

Nate

Remy Lebeau (TeamB)

unread,
Jul 18, 2005, 1:14:12 PM7/18/05
to

"Nate Lockwood" <RNLockwo...@attglobal.net> wrote in message
news:42dbce13$1...@newsgroups.borland.com...

> 1. My supervisor wants me to modify an application so that he
> can drag and drop a data file from Explorer on it and have it
> open and process the file automatically.

There are only two ways to accept dragged files from Explorer:

1) call the DragAcceptFiles() function and then intercept the WM_DROPFILES
message. When the message occurs, use DragQueryFile() to retrive the file
names and then process the files as needed.

2) derive a class from IDropTarget and then call RegisterDragDrop(). When a
drag operation is in progress, the DragEnter() and DragOver(), and
DragLeave() methods of the IDropTarget object will be called as the user is
moving the files around. When they are finally dropped, then Drop() method
will be called. At that point, you can then extract the dropped data and
use it as needed.


Gambit


Roddy Pratt

unread,
Jul 18, 2005, 5:42:00 PM7/18/05
to
You should also check out this. http://cc.borland.com/Item.aspx?id=14069

It's not actively updated, but it does what it says on the tin.

- Roddy


"Nate Lockwood" <RNLockwo...@attglobal.net> wrote in message
news:42dbce13$1...@newsgroups.borland.com...

Rudy Velthuis [TeamB]

unread,
Jul 18, 2005, 5:52:28 PM7/18/05
to
At 23:42:00, 18.07.2005, Roddy Pratt wrote:

> You should also check out this. http://cc.borland.com/Item.aspx?id=14069
>
> It's not actively updated, but it does what it says on the tin.

Please, please don't overquote:

http://blogs.teamb.com/rudyvelthuis/articles/7509.aspx
--
Rudy Velthuis [TeamB] http://velthuis.homepage.t-online.de

"Logic is in the eye of the logician."
- Gloria Steinem

Nate Lockwood

unread,
Jul 19, 2005, 6:13:23 PM7/19/05
to
Thanks for reminding me of Code Central, Roddy. I found a BCC Ver 5
example.

Nate

Nate Lockwood

unread,
Jul 19, 2005, 6:24:47 PM7/19/05
to
Remy Lebeau (TeamB) wrote:

> There are only two ways to accept dragged files from Explorer:
>
> 1) call the DragAcceptFiles() function and then intercept the WM_DROPFILES
> message. When the message occurs, use DragQueryFile() to retrive the file
> names and then process the files as needed.

I tried to implement this method but I get a stack overflow that
implicates this macro in the MainForm Class (fragment below). I don't
have any idea what causes this.

Nate

//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published:

<SKIP>

private: // private user declarations
MESSAGE void DropFile(TMessage &Message); // drag & drop handler
public: // public user declarations

<SKIP>

virtual __fastcall TMainForm(TComponent* Owner);

BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES, TMessage, DropFile);
END_MESSAGE_MAP(TMainForm);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------


JD

unread,
Jul 19, 2005, 6:49:29 PM7/19/05
to

Nate Lockwood <RNLockwo...@attglobal.net> wrote:
>Remy Lebeau (TeamB) wrote:
>
>> There are only two ways to accept dragged files from Explorer:
>>
>> 1) call the DragAcceptFiles() function and then intercept the WM_DROPFILES
>> message. When the message occurs, use DragQueryFile() to retrive the file
>> names and then process the files as needed.
>

> I tried to implement this method

The message map is defined incorrectly.

>END_MESSAGE_MAP(TMainForm);

That should read:

END_MESSAGE_MAP(TForm)

Note that I did not include the trailing semi-colon but I
don't think that including it makes a difference. I simply
don't know because I prefere to override the WndProc method
instead of using a message map(s). All I can say is that when
I have used a message map, I have not included it.

> but I get a stack overflow that implicates this macro [...]

The stack overflow is being caused by the code in your
DropFile method (which you did not show). It should look
something like:

//-------------------------------------------------------------
MESSAGE void __fastcall TForm1::DropFile(TMessage &Message)
{
HDROP hDrop = static_cast<HDROP>( Message.WParam );
int FileCount = DragQueryFile( hDrop, -1, NULL, 0 );
for( int x = 0; x < FileCount; ++x )
{
int CharacterCount = DragQueryFile( hDrop, x, NULL, 0 ) + 1; // account for NULL terminator
char *FileName = new char[ CharacterCount ];
DragQueryFile( hDrop, x, FileName, CharacterCount );
// do something with FileName
delete [] FileName;
}
DragFinish( hDrop );
}
//-------------------------------------------------------------

~ JD

Nate Lockwood

unread,
Jul 19, 2005, 7:18:57 PM7/19/05
to
JD wrote:

>
>
> The message map is defined incorrectly.
>
>
>>END_MESSAGE_MAP(TMainForm);
>
>
> That should read:
>
> END_MESSAGE_MAP(TForm)


Thanks, JD, I got it working right away and it makes perfect sense now
that you pointed it out to me.

Well it works with the semi-colon - must be an empty statement.

How do you override this method?

Nate

Remy Lebeau (TeamB)

unread,
Jul 19, 2005, 7:10:40 PM7/19/05
to

"Nate Lockwood" <RNLockwo...@attglobal.net> wrote in message
news:42dd7da3$1...@newsgroups.borland.com...

> I tried to implement this method but I get a stack overflow

<snip>
> END_MESSAGE_MAP(TMainForm);

That line needs to be this instead:

END_MESSAGE_MAP(TForm)

You need to specify the *base class*, otherwise you end up with a recursive
call that never ends.


Gambit


Remy Lebeau (TeamB)

unread,
Jul 19, 2005, 7:13:00 PM7/19/05
to

"JD" <nos...@nospam.com> wrote in message
news:42dd8379$1...@newsgroups.borland.com...

> The stack overflow is being caused by the code in your
> DropFile method (which you did not show).

Wrong. The overflow is in the END_MESSAGE_MAP macro. A MESSAGE_MAP is a
simple way to override the class's Dispatch() method. The END_MESSAGE_MAP
macro calls the Dispatch() method of the specified class for any unhandled
messages. By specifying TMainForm in the macro, TMainForm::Dispatch() calls
TMainForm::Dispatch() - and endless recursion. Hense the overflow. It has
nothing to do with the DropFiles() method at all.


Gambit


JD

unread,
Jul 19, 2005, 8:16:25 PM7/19/05
to

Nate Lockwood <RNLockwo...@attglobal.net> wrote:
>
> [...] it works with the semi-colon - must be an empty
> statement.

<duh>
Why didn't I think of that?
</duh>

> How do you override this method?

What method ... the WndProc method v/s a message map?

~ JD

JD

unread,
Jul 19, 2005, 8:14:13 PM7/19/05
to

"Remy Lebeau \(TeamB\)" <no....@no.spam.com> wrote:
>
> [...] The overflow is in the END_MESSAGE_MAP macro. A
> MESSAGE_MAP is [...]

Thanks for the detailed explaination. I never really have
understood the details of message maps.

~ JD

Remy Lebeau (TeamB)

unread,
Jul 19, 2005, 8:19:13 PM7/19/05
to

"JD" <nos...@nospam.com> wrote in message
news:42dd9755$1...@newsgroups.borland.com...

> Thanks for the detailed explaination. I never really have
> understood the details of message maps.

You can look in the sysmac.h header file for the MESSAGE_MAP macro
declarations.


Gambit


0 new messages