BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Files Dragged into form???

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage)
View previous topic :: View next topic  
Author Message
qyte
Guest





PostPosted: Tue Mar 22, 2005 10:42 pm    Post subject: Files Dragged into form??? Reply with quote



does anyone know if it is possible to enable the drag and drop of files
into a form? and to get the full path name of those files?
Back to top
Michel Corbin
Guest





PostPosted: Tue Mar 22, 2005 11:38 pm    Post subject: Re: Files Dragged into form??? Reply with quote





qyte wrote:
Quote:
does anyone know if it is possible to enable the drag and drop of files
into a form? and to get the full path name of those files?

//In the header (*.h) file :
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES,TMessage,HandleDropFiles) ;
END_MESSAGE_MAP(TForm) ;
// and in the cpp file of the form :
MESSAGE void __fastcall TFpF::HandleDropFiles(TMessage &Message)
{
int nbChar ;
HDROP hDrop=(HDROP)Message.WParam ;
int nbFiles=DragQueryFile(hDrop,-1,NULL,0) ;
char *p ;
for(int i=0;i {
nbChar=DragQueryFile(hDrop,i,NULL,0) ;
p=new char[nbChar+1] ;
DragQueryFile(hDrop,i,p,nbChar+1) ;
// here do want you want with p
delete[] p ;
}
DragFinish(hDrop) ;
}

hope it helps
Michel


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Mar 22, 2005 11:42 pm    Post subject: Re: Files Dragged into form??? Reply with quote




"qyte" <gyte (AT) vivodinet (DOT) gr> wrote


Quote:
does anyone know if it is possible to enable the drag and
drop of files into a form? and to get the full path name of
those files?

Of course it is possible. But there is nothing in the VCL to handle that,
so you have to do it manually by accessing the Win32 API directly.

The easiest way is to call DragAcceptFiles() whenever your form
creates/destroys its window handle. Then set up a message handler for the
WM_DROPFILES message, and have it call DragQueryFile() and DragFinish().

Note that this approach is outdated, and provided only for backwards
compatibility. The better way to control file dragging is to implement the
IDropTarget interface instead. Derive a class from IDropTarget and
instantiate it at runtime. Call RegisterDragDrop() and RevokeDragDrop()
when the form creates/destroys its window handle, respectively. Whenever
files are dragged over the window, the IDropTarget::DragEnter() and
IDropTarget::DragOver() methods are called. Use DragEnter() to decide
whether you will accept the files, and DragOver() to let the source know
what kind of operation will be performed when the files are dropped. When
the files are dropped, the IDropTarget::Drop() method is called. In
DragEnter() and Drop(), you are provided with an IDataObject interface that
represents the file's information.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Mar 23, 2005 12:14 am    Post subject: Re: Files Dragged into form??? Reply with quote


"Michel Corbin" <"Michel Corbin"> wrote


Quote:
//In the header (*.h) file :
snip
// and in the cpp file of the form :
snip


You forgot to show the code that calls DragAcceptFiles(). Without that, the
rest of the code will not run.


Gambit



Back to top
qyte
Guest





PostPosted: Wed Mar 23, 2005 6:44 am    Post subject: Re: Files Dragged into form??? Reply with quote

Michel Corbin wrote:
Quote:


qyte wrote:

does anyone know if it is possible to enable the drag and drop of files
into a form? and to get the full path name of those files?


//In the header (*.h) file :
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_DROPFILES,TMessage,HandleDropFiles) ;
END_MESSAGE_MAP(TForm) ;
// and in the cpp file of the form :
MESSAGE void __fastcall TFpF::HandleDropFiles(TMessage &Message)
{
int nbChar ;
HDROP hDrop=(HDROP)Message.WParam ;
int nbFiles=DragQueryFile(hDrop,-1,NULL,0) ;
char *p ;
for(int i=0;i<nbFiles;++i)
{
nbChar=DragQueryFile(hDrop,i,NULL,0) ;
p=new char[nbChar+1] ;
DragQueryFile(hDrop,i,p,nbChar+1) ;
// here do want you want with p
delete[] p ;
}
DragFinish(hDrop) ;
}

hope it helps
Michel


i did that and also call DragAcceptFiles(Form1->Handle,true) in the
constructor of the form. The problem is that the files are not accepted.
apart from that there is the following:

[C++ Warning] files.h(239): W8027 Functions containing switch are not
expanded inline

maybe yuo could tell me what am i doing wrong.
just to know i also declared the
MESSAGE void __fastcall TForm1::HandleDropFiles(TMessage &Message)
in the private part of my form.

Back to top
qyte
Guest





PostPosted: Wed Mar 23, 2005 7:09 am    Post subject: Re: Files Dragged into form??? Reply with quote

Remy Lebeau (TeamB) wrote:
The better way to control file dragging is to implement the
Quote:
IDropTarget interface instead. Derive a class from IDropTarget and
instantiate it at runtime. Call RegisterDragDrop() and RevokeDragDrop()
when the form creates/destroys its window handle, respectively. Whenever
files are dragged over the window, the IDropTarget::DragEnter() and
IDropTarget::DragOver() methods are called. Use DragEnter() to decide
whether you will accept the files, and DragOver() to let the source know
what kind of operation will be performed when the files are dropped. When
the files are dropped, the IDropTarget::Drop() method is called. In
DragEnter() and Drop(), you are provided with an IDataObject interface that
represents the file's information.

Gambit

Could You be more specific? i have no idea of how to implement
what you say.

Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Mar 23, 2005 7:33 am    Post subject: Re: Files Dragged into form??? Reply with quote


"qyte" <gyte (AT) vivodinet (DOT) gr> wrote


Quote:
i did that and also call DragAcceptFiles(Form1->Handle,true)
in the constructor of the form.

If you call it in the constructor, then don't use the form's global pointer
as it hasn't been assigned yet. Use the implicit 'this' pointer instead,
ie:

DragAcceptFiles(this->Handle, TRUE)

A better place to call it is to override the CreateWnd() and DestroyWnd()
methods, ie:

void __fastcall TForm1::CreateWnd()
{
TForm::CreateWnd();
if( HandleAllocated() )
::DragAcceptFiles(Handle, TRUE);
}

void __fastcall TForm1::DestroyWnd()
{
if( HandleAllocated() )
::DragAcceptFiles(Handle, FALSE);
TForm::DestroyWnd();
}


Quote:
The problem is that the files are not accepted.

What all do you have on your form? Is any any empty areas? Calling
DragAcceptFiles() on the form's Handle means that only the form itself, not
its child controls, can accept dragged files. That means dragging the files
onto an empty area of the form itself. If you drag files onto the child
controls, they won't accept the files, unless you call DragAcceptFiles() for
them as well.

Quote:
apart from that there is the following:

Ignore that.


Gambit



Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Mar 23, 2005 7:34 am    Post subject: Re: Files Dragged into form??? Reply with quote


"qyte" <gyte (AT) vivodinet (DOT) gr> wrote


Quote:
Could You be more specific? i have no idea of how to
implement what you say.

I suggest you search online at http://www.deja.com and
http://www.google.com. This topic is discussed in detail in many places.


Gambit



Back to top
qyte
Guest





PostPosted: Wed Mar 23, 2005 7:46 am    Post subject: Re: Files Dragged into form??? Reply with quote

Remy Lebeau (TeamB) wrote:
Quote:
"qyte" <gyte (AT) vivodinet (DOT) gr> wrote in message
news:42411068$1 (AT) newsgroups (DOT) borland.com...


i did that and also call DragAcceptFiles(Form1->Handle,true)
in the constructor of the form.


If you call it in the constructor, then don't use the form's global pointer
as it hasn't been assigned yet. Use the implicit 'this' pointer instead,
ie:

DragAcceptFiles(this->Handle, TRUE)

A better place to call it is to override the CreateWnd() and DestroyWnd()
methods, ie:

void __fastcall TForm1::CreateWnd()
{
TForm::CreateWnd();
if( HandleAllocated() )
::DragAcceptFiles(Handle, TRUE);
}

void __fastcall TForm1::DestroyWnd()
{
if( HandleAllocated() )
::DragAcceptFiles(Handle, FALSE);
TForm::DestroyWnd();
}



The problem is that the files are not accepted.


What all do you have on your form? Is any any empty areas? Calling
DragAcceptFiles() on the form's Handle means that only the form itself, not
its child controls, can accept dragged files. That means dragging the files
onto an empty area of the form itself. If you drag files onto the child
controls, they won't accept the files, unless you call DragAcceptFiles() for
them as well.


apart from that there is the following:


Ignore that.


Gambit




thanks a lot. it worked just fine. i used the two functions that you
recommended. i didn't try to use the constructor and destructor of the form.

Back to top
Michel Corbin
Guest





PostPosted: Wed Mar 23, 2005 5:18 pm    Post subject: Re: Files Dragged into form??? Reply with quote



qyte wrote:


Quote:

i did that and also call DragAcceptFiles(Form1->Handle,true) in the
constructor of the form. The problem is that the files are not accepted.
apart from that there is the following:

[C++ Warning] files.h(239): W8027 Functions containing switch are not
expanded inline


Sorry, as Gambit points it, I forgot to say :
In my programs I put
DragAcceptFiles(Handle,true) ;
in the constructor of the form.
You don't need to use this.

Michel


Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (VCL Components Usage) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.