반응형
다이얼로그는 크게 파일/폴더 탐색 두가지로 구분 되며 다음은 파일경로를 탐색하여 그 위치의 저장하는 코드이다.
1) Edit Control 생성
2) 파일 경로 설정
3) 결과
4)코드
void CTEST_CREATEDlg::OnBnClickedButton1()
{
//char szFilter[20] ;
CString szFilter = _T("txt file(*.txt)|*.txt; |ALL File(*.*(|*.*||");
CFileDialog dlg(FALSE, _T(""), NULL, OFN_OVERWRITEPROMPT, szFilter);
//CFileDialog dlg(FALSE, "bmp", "pcmon", OFN_OVERWRITEPROMPT, szFilter);
// TODO: Add your control notification handler code here
CString strFolder;
CString strPath;
CString strFileName;
CString strFolderPath;
if (IDOK == dlg.DoModal())
{
strFolder = dlg.GetFolderPath();
strPath = dlg.GetPathName();
strFileName = dlg.GetFileName();
m_strFFolder.SetWindowTextW(strFolder);
m_strFPath.SetWindowTextW(strPath);
m_strFName.SetWindowTextW(strFileName);
}
}
기존의 char 배열에 szFilter를 CString으로 구현 --> MFC에 더 효율적 (유니코드, 멀티바이트 등의 형식오류 최소화)
5) 추가
1) 경로에서 파일이름을 제외하고 경로만 추출
2) 경로에서 파일이름만 추출하고 싶을때 또는 마지막 경로depth를 추출
CString re = strPath.Mid(0, strPath.ReverseFind('\\'));//파일경로 (마지막경로제외)
CString res = strPath.Mid(strPath.ReverseFind('\\')+1, strPath.GetLength());//마지막경로
반응형
'MFC > MFC 파일 입출력' 카테고리의 다른 글
[MFC] TXT 파일 한 줄씩 읽기 (0) | 2020.07.14 |
---|---|
[MFC] 버튼 클릭 이벤트 (경로, 파일 열기) (0) | 2020.07.10 |
[MFC] 해당디렉토리가 존재하는지 여부 확인 (0) | 2020.07.07 |
[MFC] 파일 입출력 - 경로 옵션(Path option) (0) | 2020.07.02 |
C++ MFC 파일 입출력 ofstream (0) | 2020.06.25 |