2

I'm having trouble getting drag drop from Explorer to work in my app. When I create a simple VCL form app I can use the demo code in here and it works fine. My own drop target is a control aligned deep within frames and embedded forms and moving the working demo routine to this form does not work. I've tried placing a TPanel on the deeply embedded form after moving the forms other controls aside so that I can try the demo code here: way of dropping onto TPanel, this does not work either. If I place the line

DragAcceptFiles(Handle,true);

in the FormCreate of my MAIN form, the cursor indicates that I can accept files, but the same line does not seem to enable receipt of dragged files for any other deeper controls. Can anyone suggest what I might be missing? Thanks.

TLama
  • 75,147
  • 17
  • 214
  • 392
Brian Frost
  • 13,334
  • 11
  • 80
  • 154
  • The `TPanel` demo you linked to passes `Panel1.Handle` instead of the form's `Handle`. The target can be any `TWinControl`. – Ondrej Kelle Aug 29 '12 at 11:32
  • 2
    As @TOndrej says, plus: handles get recreated all the time as a result of changes to a control's properties. You may have to override the CreateWindowHandle and DestroyWindowHandle of your target control to Register/Revoke it as a drop target. Oh, and in my code I use WindowHandle instead of Handle, but I don't think that should make any real difference. – Marjan Venema Aug 29 '12 at 11:42
  • @TOndrej Yes, I used the demo code unmodified after placing a new TPanel (Panel1) on my embedded form. Should that have worked? – Brian Frost Aug 30 '12 at 07:33
  • @Marjan: I never need to revoke. The Panel demo should have worked though, surely? – Brian Frost Aug 30 '12 at 07:34

1 Answers1

0

As Marjan (and others) commented above, this turned out to be a Windows handle issue. Moving 'DragAcceptFiles()' into a later event such as FormShow solved the problem.

Brian Frost
  • 13,334
  • 11
  • 80
  • 154