Skip to content

Latest commit

 

History

History
49 lines (38 loc) · 2.72 KB

drag-and-drop-implementing-a-drop-target.md

File metadata and controls

49 lines (38 loc) · 2.72 KB
title ms.custom ms.date ms.reviewer ms.suite ms.technology ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Drag and Drop: Implementing a Drop Target | Microsoft Docs
11/04/2016
cpp-windows
article
C++
OLE drag and drop [MFC], implementing drop targets
OLE drag and drop [MFC], drop target
drag and drop [MFC], drop target
0689f1ec-5326-4008-b226-4b373c881358
10
mikeblome
mblome
ghogen

Drag and Drop: Implementing a Drop Target

This article outlines how to make your application a drop target. Implementing a drop target takes slightly more work than implementing a drop source, but it is still relatively simple. These techniques also apply to non-OLE applications.

To implement a drop target

  1. Add a member variable to each view in the application that you want to be a drop target. This member variable must be of type COleDropTarget or a class derived from it.

  2. From your view class's function that handles the WM_CREATE message (typically OnCreate), call the new member variable's Register member function. Revoke will be called automatically for you when your view is destroyed.

  3. Override the following functions. If you want the same behavior throughout your application, override these functions in your view class. If you want to modify behavior in isolated cases or want to enable dropping on non-CView windows, override these functions in your COleDropTarget-derived class.

    Override To allow
    OnDragEnter Drop operations to occur in the window. Called when the cursor first enters the window.
    OnDragLeave Special behavior when the drag operation leaves the specified window.
    OnDragOver Drop operations to occur in the window. Called when the cursor is being dragged across the window.
    OnDrop Handling of data being dropped into the specified window.
    OnScrollBy Special behavior for when scrolling is necessary in the target window.

See the MAINVIEW.CPP file that is part of the MFC OLE sample OCLIENT for an example of how these functions work together.

For more information, see:

See Also

Drag and Drop (OLE)
COleDropTarget Class