MFC drag files into the dialog box to get file information

Source: Internet
Author: User

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

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.