mfc_file_manage_4 - 8BitsCoding/RobotMentor GitHub Wiki



List Ctrl의 Owner Draw를 Fixed로 둔다. + Has Strings는 True로 둔다.

TH_ListBox 클래스를 불러온다.

#include "TW_ListBox.h"

class TW_FileListBox : public TW_ListBox
{
public:
	virtual void DrawUserItem(CDC *ap_dc, RECT *ap_rect, int a_index, void * ap_data, unsigned char a_select_flag, unsigned char a_focus_flag)
	{
		CString str;
		GetText(a_index, str);

		if (str[0] == '[') ap_dc->SetTextColor(RGB(255, 255, 128));
		else ap_dc->SetTextColor(RGB(128, 200, 200));
		ap_dc->TextOut(ap_rect->left + 5, ap_rect->top + 3, str);
	}
};
// Dlg.h
//CListBox m_left_list;
//CListBox m_right_list;
TW_FileListBox m_left_list;
TW_FileListBox m_right_list;
void CMFCApplication1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	//DDX_Control(pDX, IDC_LEFT_LIST, m_left_list);
	//DDX_Control(pDX, IDC_RIGHT_LIST, m_right_list);
}
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) {
		int dir_index = 0, file_index = 0;
		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(dir_index++, path);
				}
				else {
					ap_list_box->InsertString(dir_index + file_index++, path);
				}
				
			//}
		} while (FindNextFile(h_file_list, &file_data));
		FindClose(h_file_list);
	}
}