home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 October / pcp156b.iso / handson / files / cppwkshp / UOwnerDraw.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-07-08  |  1.5 KB  |  40 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "UOwnerDraw.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. //---------------------------------------------------------------------------
  11. __fastcall TForm1::TForm1(TComponent* Owner)
  12.     : TForm(Owner)
  13. {
  14. }
  15. //---------------------------------------------------------------------------
  16. void __fastcall TForm1::FormCreate(TObject *Sender)
  17. {
  18.     SHFILEINFO sfi;
  19.  
  20.     ListBox1->ItemHeight = GetSystemMetrics (SM_CYICON ) + 10;
  21.     ImageList1->Handle = SHGetFileInfo ("", 0, &sfi, sizeof (sfi),
  22.                          SHGFI_SYSICONINDEX | SHGFI_LARGEICON);
  23.     ImageList1->ShareImages = TRUE;
  24.  
  25. }
  26. //---------------------------------------------------------------------------
  27. void __fastcall TForm1::ListBox1DrawItem(TWinControl *Control, int Index, TRect &Rect, TOwnerDrawState State)
  28. {
  29.     TRect r = Rect;
  30.     // Clear the area to be drawn
  31.     ListBox1->Canvas->FillRect (Rect);
  32.     // Draw the icon
  33.     ImageList1->Draw (ListBox1->Canvas, Rect.Left + 5, Rect.Top + 5, Index);
  34.     // Now draw the text
  35.     r.Left += GetSystemMetrics (SM_CXICON) + 10;
  36.     DrawText (ListBox1->Canvas->Handle, ListBox1->Items->Strings [Index].c_str(), -1, (LPRECT) &r, DT_VCENTER | DT_SINGLELINE);
  37. }
  38. //---------------------------------------------------------------------------
  39.  
  40.