-1

I'm trying to create an application for Windows. In my application, when dragging items File from Windows Explorer to FormOne and then FormOne will call FormSecond show and Drop Items on FormSecond. My proplem is: I wrote code for FormSecond to handle received Files is Fine. But on FormOne I don't know how to catch dragging event mouse on FormOne to show FormSecond.

Everybody can help me, please!!! Sorry, my English is not good!

Ken White
  • 123,280
  • 14
  • 225
  • 444
Phuoc Pham
  • 11
  • 1
  • Looks too complex. Perhaps it is simpler to receive files in FormOne (create list of files), then show second from and send file list to it? – MBo Apr 28 '23 at 03:55
  • 1
    "_I writed code for FormSecond to handle received Files_" - then add that code to your question. – AmigoJack Apr 28 '23 at 06:15
  • Related/dupe: https://stackoverflow.com/questions/35188378/ – Remy Lebeau Apr 28 '23 at 07:32
  • Check [The Drag and Drop Component Suite for Delphi](http://melander.dk/delphi/dragdrop/) and [How to catch files dragged and dropped on an application from Explorer](https://delphidabbler.com/articles/article-11) – IVO GELOV Apr 28 '23 at 07:15

1 Answers1

2

When the user drags files from Windows Explorer onto a TForm, there are two different ways to handle the drop:

  1. Have the Form either:

    And then have the Form catch the WM_DROPFILES window message. The message's wParam value is an HDROP handle that you can pass to the DragQueryFile(), DragQueryPoint(), and DragFinish() APIs.

  2. Write a class that implements the IDropTarget interface, implementing the various Drag(Enter|Over|Leave)() and Drop() methods to query the file information from the provided IDataObject. Then have the Form pass an instance of that class to RegisterDragDrop(). See Transferring Shell Objects with Drag-and-Drop and the Clipboard for more details.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I have solved the problem. Thank you so much everyone! I followed this guide: https://delphidabbler.com/articles/article-24 – Phuoc Pham Apr 28 '23 at 12:04