You can have any component that has a HANDLE (or Handle in Borland) parameter accept dragged files.
To do this, call the Microsoft function DragAcceptFiles(Handle, true). To disable, set true to false. You can find more on this information in the Microsoft help files Win32 Programmer's Reference shipped with Borland.
After you set the window up, you need to handle the actual event. The event is called WM_DROPFILES. Catch this event with the provided Borland macros in your class definition for that windowed control. Note, if you want to use this for something like a TEdit, you must create a derived component TDerivedEdit (Or whatever), and then add the following code to it's class.
Now, go declare OnDrop and look at Message.wparam, this is the HANDLE of the file being dropped.
Use that handle and the function DragQueryFile(Handle, Index, StringPtr, BufferSize);
Index is the index of the file that was dropped, there could be more than 1. StringPtr is a pointer to a string that will receive the name and path of the file at Index. BufferSize is the size of the StringPtr that you've allocated. Make it MAX_PATH or something big.
You can also use DragQueryPoint(Handle, PointPtr). This will provide you with the actual client coordinates in that windowed object where the file was dropped. Useful if you have a listbox and want to know which list item it was dropped on.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.