How do I get IDropTarget to work with my Drop Handler in Delphi?

限于喜欢 提交于 2019-12-06 09:51:06

This page has an example of implementing IDropTarget in Delphi. Here is another from Jedi Code Formatter. But this library might be even better. It, amongst other things, enables dragging and dropping from Windows Explorer and therefore already supports IDropTarget in the TDropHandler class.

Use Delphi's wizards to add a standard COM out-of-process server object to your project, have it implement the IDropHandler interface (the article's code is in C++, but many of the the concepts can be applied to Delphi code as well, and some of them are already implemented by the VCL for you), and then override its virtual UpdateRegistry() method to add a couple of extra Registry keys (see the bottom of the above article) that are needed for your IDropHandler object to work with Windows Explorer double-clicking and popup menu operations.

Then, change your app code to use RegisterDragDrop() instead of DragAcceptFiles() so users can still drag-n-drop files onto your app's window via an instance of your IDropTarget-based class.

Inside your implementations of the IDropHandler methods, you can then query the passed-in IDataObject interface to see if it can provide its data in HDROP format, and if so then you can pass it to your existing WM_DROPFILES message handler (which is old and also deprecated, BTW, so you should consider removing it).

It sounds like a lot of work, but once you actually get into it, it is not very much at all. I recently implemented IDropTarget support in one of my C++Builder VCL apps and it did not take very long at all to get it working.

Once you have IDropTarget working, there are plenty of other Shell formats that you can then support if desired, such as when dropping data from non-filesystem sources.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!