Implementing a DropTarget in ATL

Implementing a DropTarget in ATL

Making a control a drop-target in ATL is not something you do very easily. The only help I found in MSDN was an example that didn't work (surprise) until I changed the datatypes of two parameters, as though they did it on purpose. That frustration out of the way, I decided to write a class that will make implementing a drop-target easy as pie. Here it is.

This class takes care of the drag-target functionality in ATL for any CWindow derivable control(= anything with an hWnd). Functions/macros you need to use are the following:

USING_CFDRAGDROP—This is a macro that needs to be included globally.

Because CFDragDropWindow has some static functions and members that need to be defined ONCE and ONCE only, include this macro in such a way that the compiler will only see it once, in the container-class that uses this class define a static function of the DRAGDROPNOTIF prototype, such as:

in which the first argument will be a vector with the names of the dropped files and the second argument the HWND of the control that the drop occurred on and the third argument the this pointer of your container-class. Next, call CFDragDropWindow's SetCallBack with this function as its first parameter and the 'this' pointer of your container-class as its second argument.

Then, call Attach with the hWnd belonging to the control you want to superclass. Now, when one or more files are dropped on the control, the DRAGDROPNOTIF function in your container-class will get called with as its arguments the dropped filenames and the 'this' pointer of your class (which you can easily cast into your class' datatype so you can use non-static methods/properties).

some mods to get it to compile in VS.Net

Posted by kenkyee
on 05/02/2005 06:30pm

In FDragDropWindow.h, I had to comment out this line:
/*BOOL CALLBACK CFDragDropWindow::EditDrop(HWND, unsigned, WPARAM, LPARAM);*/\
Also had to modify
char szTemp[MAX_PATH];\
to
WCHAR szTemp[MAX_PATH];\
But now, I get a cryptic regsvr32 error when I build my project after adding a CFDragDropWindow member variable:
error PRJ0019: A tool returned an error code from "Performing registration"

Top White Papers and Webcasts

Data integrity and ultra-high performance dictate the success and growth of many companies.
One of these companies is BridgePay Network Solutions, a recently launched and rapidly growing financial services organization that allows merchants around the world to process millions of daily credit card transactions. Due to the nature of their business, their IT team needed to strike the perfect balance between meeting regulatory-mandated data security measures with the lowest possible levels of latency and …

The 2014 State of DevOps Report — based on a survey of 9,200+ people in IT operations, software development and technology management roles in 110 countries — reveals:
Companies with high-performing IT organizations are twice as likely to exceed their profitability, market share and productivity goals.
IT performance improves with DevOps maturity, and strongly correlates with well-known DevOps practices.
Job satisfaction is the No. 1 predictor of performance against organizational …