Thanks for your link to the example, I tried the site you recommended, but I
still can't get the button to show as I wished...I followed the example and
substitute Button1 for the contrl in the example.
//---header---//
class TForm1 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
private: // User declarations
TWndMethod OriProc;
void __fastcall ButtonProc(TMessage &msg);
void __fastcall PaintButton(HDC &dc);
public: // User declarations
__fastcall TForm1(TComponent* Owner);
__fastcall ~TForm1(void);
};
//---end header---//
//---code----//
_fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
LONG exstyle = GetWindowLong( Button1->Handle, GWL_STYLE );
::SetWindowLong(Button1->Handle, GWL_STYLE, exstyle | BS_OWNERDRAW);
OriProc = Button1->WindowProc;
Button1->WindowProc = ButtonProc;
}
//--------------------------------------------------------------------------
-
__fastcall TForm1::~TForm1(void)
{
Button1->WindowProc = OriProc;
}
//--------------------------------------------------------------------------
-
void __fastcall TForm1::ButtonProc(TMessage &msg)
{
msg.Result = 0;
switch(msg.Msg)
{
case WM_DRAWITEM: PaintButton((HDC)msg.WParam);
msg.Result = 0;
break;
default: OriProc(msg);
break;
}
}
//--------------------------------------------------------------------------
void __fastcall TForm1::PaintButton(HDC &dc)
{
Graphics::TBitmap *bmp = new Graphics::TBitmap;
bmp->Width = Button1->Width;
bmp->Height =Button1->Height;
bmp->Canvas->Pen->Style = psSolid;
bmp->Canvas->Brush->Style = bsSolid;
bmp->Canvas->Brush->Color = clSkyBlue;
bmp->Canvas->RoundRect(0, 0, bmp->Width, bmp->Height, 5, 5);
bmp->Canvas->TextOut(5, 5, Button1->Caption);
::BitBlt(dc, 0, 0, bmp->Width, bmp->Height, bmp->Canvas->Handle, 0, 0,
SRCCOPY);
delete bmp;
}
//---end code----//
I have painted only a roundrect and the caption since I'm just testing it
out. However I still see the same old boring button.... What have I done
wrong? What am I missing here? Please help me. Thanks in advance.
Regards.
p/s: there was once I tried to intercept the WM_ERASEBKGND and do the
painting for that message, I did see a skyblue box flashed a brief moment at
the button's location when I put the button on the form, but it's soon
replaced by the boring old button again.
"Remy Lebeau (TeamB)" <
XXXX@XXXXX.COM >wrote in message