Many software support directly drag the file into the function of processing, specific, such as Storm Audio, the video or audio files will be dragged into the automatically start playing, then this function in MFC how to implement it? In fact, it is very simple, the following steps:
First step: Set the Accept Files property value in the dialog box properties to True
Step Two: Add Wm_dropfiles messages
Step three: Define the response function for the wm_dropfiles message as follows:
void Cdragfiletodlgdlg::ondropfiles (Hdrop hdropinfo) {WCHAR Szpath[max_path] = L ""; UINT totalfile = Dragqueryfile (Hdropinfo, 0xFFFFFFFF, szpath, MAX_PATH);//function returns the length or number of files dragged into the file, mainly used to get the path and name of the dragged file// The first parameter is the handle of the structure that the file is placed in//the second parameter is the mark of the first file, and set to 0xFFFFFFFF returns the number of dragged-in files//The third parameter is the file name buffer for the first address//fourth parameter is the size of the file name buffer for (int filenum = 0; FileNum < Totalfile; filenum++) {UINT pathlenght = Dragqueryfile (Hdropinfo, FileNum, szpath, MAX_PATH);//Read into section Totalfile+ 1 The path dragged into the file into Szpath CString filepath (szpath, pathlenght);//Convert the Read file path to CString format}cdialogex::ondropfiles (hdropinfo);}
OK, so we've completed the interactive function of the dialog box and the file mentioned above.
MFC drag files into the dialog box to get file information