How to drag and drop files in and out of applications by using OLE drag and drop (288929)



The information in this article applies to:

  • Microsoft Visual C++ 2005 Express Edition
  • Microsoft Visual C++ .NET (2002)
  • Microsoft Visual C++, 32-bit Enterprise Edition 6.0
  • Microsoft Visual C++, 32-bit Professional Edition 6.0
  • Microsoft Visual C++, 32-bit Learning Edition 6.0

This article was previously published under Q288929

SUMMARY

This sample demonstrates how to drag and drop files in and out of applications by using OLE drag and drop. It shows how to drag a file to your application and how to drag a file from your application to other places that can accept files. The information in this article supplements the following Microsoft Knowledge Base articles:

135299 Using MFC OLE Drag and Drop to Drag Text Between Windows

185572 HOWTO: Get Dropped File Names Using OLE Drag and Drop

MORE INFORMATION

Developers have generally used WM_DROPFILES message to handle files dropped from other applications. This message is sent when the user drops a file on the window of an application that has registered itself as a recipient of dropped files.

On the other hand, your application can respond to mouse event to support dragging files to other applications. OLE drag and drop supports this functionality. Both techniques involve passing a global HDROP (drop structure handle) from the source to the target. WM_DROPFILES passes this handle in the WPARAM value. OLE drag and drop passes the HDROP with the data object.

In the sample project provided in this article, CFileDropListCtrl is the most important class. Its OnDropFiles method shows how to deal with the file that is dragged in. The OnLButtonDown method shows how to drag file to another application.


The following file is available for download from the Microsoft Download Center:
Release Date: May-02-2001

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Modification Type:MajorLast Reviewed:12/31/2005
Keywords:kbdownload kbfile kbSample KB288929 kbAudDeveloper