Unit1.cpp
上传用户:lhxd_sz
上传日期:2014-10-02
资源大小:38814k
文件大小:3k
- //---------------------------------------------------------------------------
- #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;
- }
- //---------------------------------------------------------------------------