Board index » cppbuilder » WM_DROPFILES on ListView

WM_DROPFILES on ListView


2006-10-20 01:04:22 AM
cppbuilder25
Hi,
I wrote a code to intercept WM_DROPFILES in a form, now I'd like to move it
on a ListView component inside the form.
I guess I could create a CustomListView and initialize it at runtime but
this way I can't see it in the Form editor and modify it visually.
How can I solve this problem?
 
 

Re:WM_DROPFILES on ListView

"4N" < XXXX@XXXXX.COM >wrote in message
Quote
I wrote a code to intercept WM_DROPFILES in a form, now
I'd like to move it on a ListView component inside the form.
You need to subclass the ListView's WindowProc property, as then specify the
ListView's Handle when calling DragAcceptFiles(). You will also have to
intercept the CM_RECREATEWND message so that you can call DragAcceptFiles()
again whenever the ListView's Handle is recreated by the VCL internals. For
example:
TWndMethod OldWndProc;
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
OldWndProc = ListView1->WindowProc;
ListView1->WindowProc = ListViewWndProc;
DragAcceptFiles(ListView1->Handle, TRUE);
}
void __fastcal TForm1::ListViewWndProc(TMessage &Message)
{
switch( Message.Msg )
{
case WM_DROP_FILES:
{
//...
break;
}
case CM_RECREATEWND:
{
DragAcceptFiles(ListView1->Handle, FALSE);
OldWndProc(Message);
DragAcceptFiles(ListView1->Handle, TRUE);
break;
}
default:
OldWndProc(Message);
break;
}
}
Quote
I guess I could create a CustomListView and initialize it at runtime
but this way I can't see it in the Form editor and modify it visually.
You can if you put it into a package and then install it into the Component
Palette.
Gambit
 

Re:WM_DROPFILES on ListView

Quote
You can if you put it into a package and then install it into the
Component Palette.
I hate this... but I guess it can't be helped.
Thanks.
 

{smallsort}

Re:WM_DROPFILES on ListView

4N wrote:
Quote
>You can if you put it into a package and then install it into the
>Component Palette.

I hate this... but I guess it can't be helped.
It may seem like busywork, but this is the best approach from an OO
standpoint.
If you still don't want create a package, you could could create a
wrapper class that cleans up the WindowProc code that Remy posted.
Something like:
class TDropFilesHandler : TWinControl
{
public:
TDropFilesHandler(TWinControl target, TComponent Owner);
...
}
// usage
__fastcall TForm1::TForm1(TComponent *Owner)
: TForm(Owner)
{
dropHandler = new TDropHandler(ListView1, this);
}
H^2