//--------------------------------------------------------------------------- #include #pragma hdrstop //--------------------------------------------------------------------------- #include "UpdateListBoxUnit.h" #include "GlobalUnit.h" #pragma package(smart_init) //--------------------------------------------------------------------------- __fastcall UpdateListBoxUnit::TListBox::TListBox(System::Classes::TComponent* AOwner) : TSkinListBox(AOwner) { m_imgBackground = new TBitmap(); m_imgBackground->LoadFromResourceName(int(HInstance),"CustomPanelBackground"); m_pFntText = new TFont(); m_pFntText->Name = "黑体"; m_pFntText->Size = 9; } //--------------------------------------------------------------------------- __fastcall UpdateListBoxUnit::TListBox::~TListBox() { if( m_imgBackground ){ delete m_imgBackground; } if( m_pFntText ){ delete m_pFntText; } } //--------------------------------------------------------------------------- void __fastcall UpdateListBoxUnit::TListBox::WMPaint(Winapi::Messages::TWMPaint &Message) { DefaultHandler( &Message ); if( Items->Count==0 ){ TRect rectClient(0,0,ClientWidth,ClientHeight); //绘制底图 rectClient.left++; rectClient.right--; rectClient.top++; rectClient.bottom--; Canvas->StretchDraw( rectClient, m_imgBackground ); } } //--------------------------------------------------------------------------- void __fastcall UpdateListBoxUnit::TListBox::DrawItem(int Index, const System::Types::TRect &Rect, Winapi::Windows::TOwnerDrawState State) { TRect rcDraw, rcOrig = Rect; if( rcOrig.Width()StretchDraw( rcDraw, m_imgBackground ); Canvas->Brush->Style = bsClear; if( State.Contains(odSelected) ){ Canvas->Font->Color = clBlack; if(State.Contains(odFocused)) DrawFocusRect(Canvas->Handle, &Rect); } Canvas->TextOut( Rect.Left+8, Rect.Top+1, Items->Strings[Index]); if( Index==Items->Count-1 && Rect.bottomStretchDraw( rcBlank, m_imgBackground ); } }