李国帅 于2009-07-08 17:21
选择一个文件
//CFileDialog dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("AVI文件(*.avi)|*.AVI|mp4文件(*.mp4)|*.MP4|jpg文件(*.jpg)|*.jpg||")); CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, _T("媒体文件(*.avi;*.mp4)|*.AVI;*.MP4||")); if (IDOK == dlg.DoModal()) { CString aviName = dlg.GetPathName(); CString extname = dlg.GetFileExt(); //返回选定文件的扩展文件名 extname.MakeLower(); } |
选择多个文件
CString fileNameArray[numberOfFileNames];// Create array for file names. void CCombinDlg::OnBnClickedBtnAdd() { // Create dialog to open multiple files. CFileDialog Filedlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_ALLOWMULTISELECT | OFN_EXPLORER, _T("AVI文件(*.avi)|*.AVI||")); // Create buffer for file names. const DWORD numberOfFileNames = 32;//最多允许32个文件 const DWORD fileNameMaxLength = MAX_PATH + 1; const DWORD bufferSize = (numberOfFileNames * fileNameMaxLength) + 1; TCHAR* filenamesBuffer = new TCHAR[bufferSize]; // Initialize beginning and end of buffer. filenamesBuffer[0] = NULL;//必须的 filenamesBuffer[bufferSize - 1] = NULL; // Attach buffer to OPENFILENAME member. Filedlg.m_ofn.lpstrFile = filenamesBuffer; Filedlg.m_ofn.nMaxFile = bufferSize; int iCtr = 0; if (IDOK == Filedlg.DoModal()) { CString aviName; POSITION pos = Filedlg.GetStartPosition(); while (pos != NULL) { aviName = Filedlg.GetNextPathName(pos);//返回选定文件文件名// Retrieve file name(s). fileNameArray[iCtr] = aviName; iCtr++; } } delete[] filenamesBuffer;//Release file names buffer. }
来源:CSDN
作者:微澜-
链接:https://blog.csdn.net/lgs790709/article/details/78900419