linquize
linquize

Reputation: 20396

MFC CListCtrl drag file to Windows Explorer

I am writing an MFC application.

I want to drag file from a CListCtrl in my application to Windows Explorer.

How to do that?

Upvotes: 1

Views: 1846

Answers (2)

thomiel
thomiel

Reputation: 2965

You need to override OnDrop() in your CListCtrl derived class and provide a COleDataSource.

Upvotes: 3

snowdude
snowdude

Reputation: 3874

You need to hook up LVN_BEGINDRAG to detect the beginning of a drag drop and then call DoDragDrop with an IDataObject based data source populated with the file information (easiest format to handle is CF_HDROP). The Windows shell handles everything else.

Fortunately much of the leg work has already been done for you in the MFC class COleDataSource. There are also some great examples available:

Code Project - How to Implement Drag and Drop Between Your Program and Explorer

MSDN - Transferring Shell Objects with Drag-and-Drop and the Clipboard

Upvotes: 4

Related Questions