[ATL/WTL]_[primary]_[drag and drop files into the window.

label WM_DROPFILESWTLMFCDrag and dropDrag-drop
417 people read comment(1) Collection report


1 software needs to be supported from the desktop to drag the file to the software, to avoid the document to open the window to select the file, so much faster, when you need to support drag and drop windows and drop. drag

2 software needs to copy files to remote or equipment, and support for drag and drop is very convenient.

Two schemes:

1, if it is a Windows window procedure, you can use the WM_DROPFILES to achieve listening to the news, here to explain the first, more convenient.


2 if you do not want to listen to WM_DROPFILES messages, or to achieve the window between the drag and drop, or drag the text to the window, or to achieve some of the Shell operation, the need to achieve IDropTarget.

This method is more powerful, more widely used, but it is also more complex, and because of the COM programming is not familiar with, so do not consider.


Step of the first scheme:

1 windows in the creation, call:: DragAcceptFiles (m_hWnd, bAccept); set the window to support the receiving and dropping files.

2 in the window to listen to the message WM_DROPFILES, and realize the message monitoring function.

OnDropFiles LRESULT (uMsg UINT, wParam WPARAM, lParam LPARAM, BOOL&, bHandled);

Https:// (v=vs.85).Aspx

After the message processing function to achieve the desired logic.

SzFilePathName[_MAX_PATH+1] TCHAR = {0};
HDrop HDROP = (HDROP) wParam;
NFileCount UINT =:: DragQueryFile (hDrop, 0xFFFFFFFF, NULL, 0);
Std:: vector<std:: paths wstring>;
For (nIndex=0 UINT; nFileCount nIndex<; ++nIndex)
: DragQueryFile (hDrop, nIndex, szFilePathName, _MAX_PATH);
Paths.push_back (szFilePathName);
: DragFinish (hDrop);

Function can be used to view the MSDN.

:: DragQueryFile: used to query the file path into the.

: DragFinish: note, must be transferred to the release of memory, or there will be a memory leak.

reference resources

Https:// P=14183/?

step on
Guess you're looking for
View comments
* the above user comments only represent their personal views, does not represent the views or position of the CSDN website
    personal data
    • visit334288 times
    • Integral:Five thousand five hundred and thirty-seven
    • Grade
    • Rank:2595th name
    • original210
    • Reproduced:13
    • Translation:2
    • Comments:94
    There are 1 questions message or send private messages. 2 is too slow to directly add QQ ask [632994155]
    Blog column
    Latest comments