[Atl/wtl]_[Primary]_[drag and drop files to the window]

Source: Internet
Author: User


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]

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.