⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 unit1.cpp

📁 有视频
💻 CPP
字号:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index,
      TRect &Rect, TOwnerDrawState State)
{
  Graphics::TBitmap *pBitmap;
  int     Offset = 2;

  TCanvas *pCanvas = ((TListBox *)Control)->Canvas;
  pCanvas->FillRect(Rect); // clear the rectangle

  pBitmap = (Graphics::TBitmap *)((TListBox *)Control)->Items->Objects[Index];

  if (pBitmap)
  {
    pCanvas->CopyRect(Bounds(Rect.Left + Offset, Rect.Top, pBitmap->Width, pBitmap->Height), pBitmap->Canvas,Bounds(0, 0, pBitmap->Width, pBitmap->Height));
    Offset += pBitmap->Width + 4;   // add four pixels between bitmap and text
  }
  // display the text
  pCanvas->TextOut(Rect.Left + Offset, Rect.Top+6,((TListBox *)Control)->Items->Strings[Index]);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DirectoryListBox1Change(TObject *Sender)
{
  ListBox1->Clear();
  TSearchRec sr;
  int iAttributes = 0;
  iAttributes |=faHidden;
  iAttributes |=faSysFile;

  if (FindFirst(DirectoryListBox1->Directory+"\\*.*", iAttributes, sr) == 0)
  {
    AddFileToList(sr.Name,sr.Attr);
    while (FindNext(sr) == 0)
    {
      AddFileToList(sr.Name,sr.Attr);
    }
    FindClose(sr);
  }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AddFileToList(AnsiString filename,int attr)
{
  switch(attr)
  {
    case faSysFile:
      ListBox1->Items->AddObject(filename,Image4->Picture->Bitmap);
      break;
    case faHidden:
      ListBox1->Items->AddObject(filename,Image3->Picture->Bitmap);
      break;
    case faReadOnly:
      ListBox1->Items->AddObject(filename,Image2->Picture->Bitmap);
      break;
    case faArchive:
      ListBox1->Items->AddObject(filename,Image1->Picture->Bitmap);
      break;
    default:
      break;
  }
}
//---------------------------------------------------------------------------


void __fastcall TForm1::DriveComboBox1Change(TObject *Sender)
{
  DirectoryListBox1->Drive=DriveComboBox1->Drive;
}
//---------------------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -