장성호님의 3번 SubClassing 예제를 올립니다.
하지만 버튼이 Down했을때의 이벤트를 몰라 걍 버튼 모양만 띄었습니당. 헤헤~
헤더파일
typedef void __fastcall (__closure *TOnWndProc)(Messages::TMessage &Message);
class TForm1 : public TForm
{
__published: // IDE-managed Components
TSpeedButton *SpeedButton1;
private: // User declarations
public: // User declarations
__fastcall TForm1(TComponent* Owner);
TOnWndProc FBtnWndProc;
void __fastcall BtnWndProc(Messages::TMessage &Message);
void __fastcall DrawPaint(HDC AHdc);
};
Cpp화일
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
FBtnWndProc = SpeedButton1->WindowProc;
SpeedButton1->WindowProc = BtnWndProc;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BtnWndProc(Messages::TMessage &Message)
{
switch(Message.Msg)
{
case WM_PAINT:
DrawPaint((HDC)Message.WParam);
return;
}
FBtnWndProc(Message);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::DrawPaint(HDC AHdc)
{
Graphics::TCanvas *canvas = new Graphics::TCanvas();
canvas->Handle = AHdc;
canvas->Brush->Color = clGreen;
canvas->FillRect(canvas->ClipRect);
Frame3D(canvas, canvas->ClipRect, clWhite, clGray, 2);
delete canvas;
}
장성호 님이 쓰신 글 :
: 간단하게 하는 방법은 잘모르구요
:
:
: 몇가지 팁 을 말씀드리면
:
: 1. Color 설정지원하는 외부 Button Component를 사용합니다.
: ==> 가장 쉬움
: 예)
http://cbuilder.borlandforum.com/impboard/impboard.dll?action=read&db=component&no=502
:
: 2. 이건 트릭인데
: TPanel 위에 TSpeedButton을 올려두고
: SpeedButton을 Transparent = true 로 하고 Flat=true로 합니다.
: 그런후 Panel의 Color를 바꿉니다.
:
: 그러면 Panel의 색이 그대로 가져가는데.... 쉽지만 몇가지 문제가 있긴 하죠
:
: 3. TButton의 Paint 이벤트에 직접 draw해줍니다.
: 컴포넌트를 만들거나, 이미지 입히는것이랑 똑같은 방식으로 하는데...
:
: 이방법의 문제는 TButton에서는 OnPaint 이벤트가 없다는것입니다.
: 그러기때문에 WM_PAINT 메세지를 받도록 SubClassing해야합니다.
:
:
: 그럼....
:
:
:
:
:
:
: 이한진 님이 쓰신 글 :
: : 이번에 빌더를 시작한 초보입니다.
: : 다름이 아니라 버튼의 바탕색을 바꿀수 없나 해서요
: : 적색과 녹색을 사용했으면 하는데, 않되는것인가요?
: : 이미지 파일을 불러오거나 하려니 좀 그런것 같고..
: : 이왕이면 여타 그래픽 파일을 쓰지 않으려 하거든요
: : 스피드 버튼 말고 바탕색을 바꿀수 있는것이 있나요?
: : 고수님들의 답변 부탁드려요..