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);
    List->AddItem(item);

    // add the size of the item
    //
    itoa((findData.nFileSizeHigh * MAXDWORD) + findData.nFileSizeLow, text, 10);
    item.SetText(text);
    List->SetItem(item, -1, 1);

    // add the type of the item
    //
    if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
      item.SetText("Directory");
    else
      item.SetText("File");
    List->SetItem(item, -1, 2);

    // add the time modified
    //
    FileTimeToSystemTime(&findData.ftLastWriteTime, &st);
    TTime time(TDate(st.wDay, st.wMonth, st.wYear), st.wHour, st.wMinute, st.wSecond);
    strcpy(text, time.AsString().c_str());
    item.SetText(text);
    List->SetItem(item, -1, 3);
  }
  while (FindNextFile(findHandle, &findData));

  FindClose(findHandle);
}

Return to Adding Items


DEFINE_RESPONSE_TABLE1(TLWWindow, TWindow)
  // ...
  EV_NM_DBLCLK(kListId, ListDoubleClick),
  // ...
END_RESPONSE_TABLE;

void TLWWindow::ListDoubleClick()
{
  // find the first item that is selected
  //
  for (int i = 0, imax = List->GetItemCount(); i < imax; i++)
    if (List->GetItemState(i, TListWindItem::Selected))
    {
      TListWindItem nameItem(*List, i, 0);
      TListWindItem typeItem(*List, i, 2);

      // if the item is a folder, change to it and refresh
      //
      if (!strcmp(typeItem.GetText(), "Directory"))
      {
        SetCurrentDirectory(nameItem.GetText());
        AddListItems();
      }

      break;
    }
}

Return to Responding To Events