MFC 弹出文件夹、文件对话框

文件夹选择对话框

CString m_strFileOut = _T("");  

	TCHAR szSelected[MAX_PATH];
	BROWSEINFO bi;
	LPITEMIDLIST pidl;

	bi.hwndOwner = this->m_hWnd;
	bi.pidlRoot = NULL;
	bi.pszDisplayName = szSelected;
	bi.lpszTitle = _T("请选择文件夹");
	bi.ulFlags = BIF_RETURNONLYFSDIRS;
	bi.lpfn = NULL;
	bi.lParam = NULL;
	bi.iImage = NULL;

	if ((pidl = SHBrowseForFolder(&bi)) != NULL)
	{
		if (SUCCEEDED(SHGetPathFromIDList(pidl, szSelected))) 
		{
			m_strFileOut = szSelected;  	
		}
	}

	m_str_dirname = m_strFileOut+_T("\\");
	SetDlgItemText(IDC_EDIT_SOURCEDIR, m_strFileOut);

文件选择对话框

CFileDialog dlg(TRUE, L"txt", NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, L"(*.txt)|*.txt||");
	if (dlg.DoModal() == IDOK)
	{
		m_str_dstname = dlg.GetPathName();
		SetDlgItemText(IDC_EDIT_DSTFILE, m_str_dstname);
		UpdateData(FALSE);
	}

你可能感兴趣的:(【道阻且长C++】,【MFC】,mfc,c++)