void TLWWindow::AddListColumns()
{
List->InsertColumn(0, TListWindColumn("Name", 200));
List->InsertColumn(1, TListWindColumn("Size", 80, TListWindColumn::Right));
List->InsertColumn(2, TListWindColumn("Type", 120));
List->InsertColumn(3, TListWindColumn("Modified", 200));
}
This code is for Borland C++ 5.02 only. If you are using Borland C++ 5.01, click here.
void TLWWindow::AddListItems()
{
HANDLE findHandle;
WIN32_FIND_DATA findData;
char text[256];
SYSTEMTIME st;
// remove all of the items from the list
//
List->DeleteAllItems();
// open the current directory for reading
//
if ((findHandle = FindFirstFile(".\\*.*", &findData)) == INVALID_HANDLE_VALUE)
return;
// add each of the files in the directory
//
do
{
// add the name
//
TListWindItem item(findData.cFileName);
item.SetImageIndex(findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ? 1 : 0);
int index = List->AddItem(item);
// add the size of the item
//
itoa((findData.nFileSizeHigh * MAXDWORD) + findData.nFileSizeLow, text, 10);
List->SetItemText(index, 1, text);
// add the type of the item
//
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
List->SetItemText(index, 2, "Directory");
else
List->SetItemText(index, 2, "File");
// add the time modified
//
FileTimeToSystemTime(&findData.ftLastWriteTime, &st);
TTime time(TDate(st.wDay, st.wMonth, st.wYear), st.wHour, st.wMinute, st.wSecond);
List->SetItemText(index, 3, time.AsString().c_str());
}
while (FindNextFile(findHandle, &findData));
FindClose(findHandle);
}