mfc_file_manage_2 - 8BitsCoding/RobotMentor GitHub Wiki
BOOL CMFCApplication1Dlg::OnInitDialog()
{
CDialogEx::OnInitDialog();
// μ΄ λν μμμ μμ΄μ½μ μ€μ ν©λλ€. μμ© νλ‘κ·Έλ¨μ μ£Ό μ°½μ΄ λν μμκ° μλ κ²½μ°μλ
// νλ μμν¬κ° μ΄ μμ
μ μλμΌλ‘ μνν©λλ€.
SetIcon(m_hIcon, TRUE); // ν° μμ΄μ½μ μ€μ ν©λλ€.
SetIcon(m_hIcon, FALSE); // μμ μμ΄μ½μ μ€μ ν©λλ€.
// TODO: μ¬κΈ°μ μΆκ° μ΄κΈ°ν μμ
μ μΆκ°ν©λλ€.
wchar_t temp_path[MAX_PATH];
int len = GetCurrentDirectory(MAX_PATH, temp_path); // C:\temp μ΄λ°μμΌλ‘ κ²½λ‘κ° λ€μ΄μ΄
temp_path[len++] == '\\'; // C:\temp\λ‘ κ²½λ‘λͺ
μ μμ
temp_path[len] == 0; // λ§μ§λ§μ NULLλ£λ κ²λ μμ§ λ§κΈ°
SetDlgItemText(IDC_L_PATH_EDIT, temp_path);
SetDlgItemText(IDC_R_PATH_EDIT, temp_path);
DirToList(&m_left_list, temp_path);
DirToList(&m_right_list, temp_path);
return TRUE; // ν¬μ»€μ€λ₯Ό 컨νΈλ‘€μ μ€μ νμ§ μμΌλ©΄ TRUEλ₯Ό λ°νν©λλ€.
}
void CMFCApplication1Dlg::DirToList(CListBox* ap_list_box, CString a_path)
{
// κΈ°μ‘΄νλͺ©μ κ±°
ap_list_box->ResetContent();
CString path;
WIN32_FIND_DATA file_data;
a_path += L"\\";
HANDLE h_file_list = FindFirstFile(a_path+L"*.*", &file_data);
if (h_file_list != INVALID_HANDLE_VALUE) {
do {
//if (!(file_data.cFileName[0] == '.' && file_data.cFileName[1] == 0)) {// *.* ν°λ ν 리 μ μΈνκΈ°
path = file_data.cFileName;
if (file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) path = L"[" + path + L"]";
ap_list_box->InsertString(-1, path);
//}
} while (FindNextFile(h_file_list, &file_data));
FindClose(h_file_list);
}
}
void CMFCApplication1Dlg::ChangeDir(CListBox * ap_list_box, int a_path_ctrl_id)
{
CString str, path;
int index = ap_list_box->GetCurSel();
ap_list_box->GetText(index, str);
if (str[0] == '[') { // λλ ν°λ¦¬
GetDlgItemText(a_path_ctrl_id, path);
str.TrimLeft('[');
str.TrimRight(']');
if (str == L"..") {
// ex. c:\temp\aa -> c:\temp\
path.TrimRight('\\');
int pos = path.ReverseFind('\\');
path.Delete(pos + 1, path.GetLength() - pos - 1);
}
else {
// ex. c:\temp\ + aa -> c:\temp\aa
path += L"\\";
path += str;
// ex. c:\temp\aa -> c:\temp\aa\
//path += L"\\";
}
SetDlgItemText(a_path_ctrl_id, path);
DirToList(ap_list_box, path);
}
}
void CMFCApplication1Dlg::OnLbnDblclkLeftList()
{
ChangeDir(&m_left_list, IDC_L_PATH_EDIT);
}
void CMFCApplication1Dlg::OnLbnDblclkRightList()
{
ChangeDir(&m_right_list, IDC_R_PATH_EDIT);
}