Transparent ListBox component


2005-12-21 07:56:11 PM
cppbuilder43
Hi,
I want to write a transarent TListBox component.
I found a delphi code in the net and tried to translate in C++ Builder.
But, it does not support scrolling lists.
How can I handle scrolling?
Any help will be highly appreciated!
Thanks in advance!
Here is the code:
// Header file
class PACKAGE TTransListBox : public TListBox
{
private:
protected:
virtual void __fastcall CreateParams(Controls::TCreateParams &Params);
virtual void __fastcall DrawItem(int Index, const Types::TRect &Rect,
Windows::TOwnerDrawState State);
MESSAGE void __fastcall WMEraseBkgnd(Messages::TWMEraseBkgnd &Message);
public:
virtual void __fastcall SetBounds(int ALeft, int ATop, int AWidth, int
AHeight);
__fastcall TTransListBox(TComponent* Owner);
__published:
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_ERASEBKGND, TWMEraseBkgnd, WMEraseBkgnd)
END_MESSAGE_MAP(TListBox)
__property Style = {default=lbOwnerDrawFixed};
__property Ctl3D = {default=false};
__property BorderStyle = {default=bsNone};
};
//--------------------------------------------------------------------------
-
#endif
// source file
//--------------------------------------------------------------------------
-
#include <vcl.h>
#pragma hdrstop
#include "TransListBox.h"
#pragma package(smart_init)
//--------------------------------------------------------------------------
-
static inline void ValidCtrCheck(TTransListBox *)
{
new TTransListBox(NULL);
}
//--------------------------------------------------------------------------
-
__fastcall TTransListBox::TTransListBox(TComponent* Owner)
: TListBox(Owner)
{
Ctl3D = false;
BorderStyle = bsNone;
Style = lbOwnerDrawFixed;
}
//--------------------------------------------------------------------------
-
namespace Translistbox
{
void __fastcall PACKAGE Register()
{
TComponentClass classes[1] = {__classid(TTransListBox)};
RegisterComponents("Standart", classes, 0);
}
}
//--------------------------------------------------------------------------
-
void __fastcall TTransListBox::CreateParams(Controls::TCreateParams &Params)
{
TListBox::CreateParams(Params);
Params.ExStyle |= WS_EX_TRANSPARENT;
}
//--------------------------------------------------------------------------
-
MESSAGE void __fastcall TTransListBox::WMEraseBkgnd(Messages::TWMEraseBkgnd
&Message)
{
Message.Result = 1;
}
//--------------------------------------------------------------------------
-
void __fastcall TTransListBox::SetBounds(int ALeft, int ATop, int AWidth,
int AHeight)
{
bool tlbVisible;
tlbVisible = (Parent != NULL) && IsWindowVisible(Handle);
if (tlbVisible) ShowWindow(Handle, SW_HIDE);
inherited::SetBounds(ALeft, ATop, AWidth, AHeight);
if (tlbVisible) ShowWindow(Handle, SW_SHOW);
}
//--------------------------------------------------------------------------
-
void __fastcall TTransListBox::DrawItem(int Index, const Types::TRect &Rect,
Windows::TOwnerDrawState State)
{
TBrushStyle FoundStyle;
TRect R;
FoundStyle = Canvas->Brush->Style;
R = Rect;
MapWindowPoints(Handle, Parent->Handle, (LPPOINT)&R, 2);
InvalidateRect(Parent->Handle, &R, true);
Parent->Update();
Canvas->Brush->Style = bsClear;
inherited::DrawItem(Index, Rect, State);
Canvas->Brush->Style = FoundStyle;
}
}
//--------------------------------------------------------------------------
-