By dropfile target I mean the application that can process file names dropped into it.
To modify your application to become a dropfile target all you have to do is to create your window
with the extended window style
WS_EX_ACCEPTFILES and handle
Another way is to create a window and then call the following API function:
DragAcceptFiles(HWND hWnd, BOOL bAccept)
that turns the
style on or off based on the value of the
The obvious solution would be to create a class to encapsulate the above mentioned logic. So I present
CDropFileTarget that does just that.
Using the code
It's very easy to use
CDropFileTarget class. Just follow the following steps:
CDropFileTarget to the inheritance chain:
class CMainDlg : public CDialogImpl<CMainDlg>,
CHAIN_MSG_MAP statement to the message map of your class:
OnInitDialog() function register your class as a dropfile target
LRESULT OnInitDialog(UINT , WPARAM ,
LPARAM , BOOL& )
- Add the following public function to process the dropped file
void ProcessFile(LPCTSTR lpszPath)
This class is very simple and may not meet all your requirements, but if you only need to
allow your window to accept dropped files and process them then this class is for you.
THIS SOFTWARE AND THE ACCOMPANYING FILES ARE DISTRIBUTED "AS IS" AND WITHOUT ANY WARRANTIES WHETHER EXPRESSED OR IMPLIED. NO RESPONSIBILITIES FOR POSSIBLE DAMAGES CAN BE TAKEN. THE USER MUST ASSUME THE ENTIRE RISK OF USING THIS SOFTWARE.