Scene:
1. The software needs to support drag files from the desktop to the software, to avoid from the File open window to select files, so much more efficient, then need to window support drag-and-drop technology. Drag and drop.
2. The software needs to copy files to remote or device, it is convenient to support drag and drop.
Two scenarios:
1. If it is a Windows window program, you can use the Listening wm_dropfiles message to achieve, here to explain the first kind, more convenient.
http://blog.csdn.net/laogaoav/article/details/9152181
2. If you do not want to listen for wm_dropfiles messages, or to implement drag-and-drop between windows, or drag and drop text into a window, or implement some shell operations, you need to implement IDropTarget.
This method is more powerful, wider in scope, but more complex to implement, and is not considered for the time being because it is unfamiliar with COM programming.
Https://msdn.microsoft.com/en-us/library/ms679679.aspx
Steps for the first scenario:
1. After the window is created, call::D ragacceptfiles (M_hwnd, baccept); The Settings window supports receiving drag-and-drop files.
2. Listen for message wm_dropfiles on the window and implement the message listener function.
LRESULT ondropfiles (UINT umsg, WPARAM WPARAM, LPARAM LPARAM, bool& bhandled);
https://msdn.microsoft.com/en-us/library/windows/desktop/bb774303 (v=vs.85). aspx
Then implement the desired logic in the message handler function.
TCHAR Szfilepathname[_max_path+1] = {0}; Hdrop Hdrop = (hdrop) WParam; UINT Nfilecount =::D ragqueryfile (Hdrop, 0xFFFFFFFF, NULL, 0);std::vector<std::wstring> paths;for (UINT nindex=0; nindex< Nfilecount; ++nindex) {::D ragqueryfile (Hdrop, NIndex, Szfilepathname, _max_path);p aths.push_back (Szfilepathname);}::D Ragfinish (Hdrop);
function using view MSDN.
::D ragqueryfile: Used to query the path of the file being dragged into.
::D ragfinish: note, be sure to release memory, otherwise there will be a memory leak.
[atl/wtl]_[Primary]_[drag and drop files to window]