MFC弹出选择文件和选择文件夹代码

 1 选择文件夹
 2 
 3     TCHAR    szSelectedDir[300];
 4     BROWSEINFO     bi;
 5     ITEMIDLIST *il;
 6     bi.hwndOwner = m_hWnd;
 7     bi.pidlRoot = NULL;
 8     bi.pszDisplayName = NULL;
 9     bi.lpszTitle = _T("Excel位?置?选?择?");
10     bi.ulFlags = BIF_RETURNONLYFSDIRS;
11     bi.lpfn = NULL;
12     bi.lParam = 0;
13     bi.iImage = 0;
14     il = SHBrowseForFolder(&bi);
15     if(il==NULL) 
16         return;
17 
18     SHGetPathFromIDList(il, szSelectedDir);
19     GetDlgItem(IDC_EDIT1)->SetWindowText(szSelectedDir);
20     excel_dir = szSelectedDir;

 

 1 选择文件    
 2     static TCHAR BASED_CODE szFilter[] = _T("数簓据Y库a文?件t(*.xlsx)|*.xlsx||");
 3 
 4     CFileDialog    dlg(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,this);
 5     CString fileName;
 6     if(dlg.DoModal() == IDOK)
 7     {
 8         UpdateData(FALSE);
 9     }
10     GetDlgItem(IDC_EDIT1)->SetWindowText(dlg.GetPathName());
11     excel_path = dlg.GetPathName();

 

你可能感兴趣的:(MFC弹出选择文件和选择文件夹代码)