48 enum { TIMERID_DRAW = 1 };
52 BUTTON = DFCS_BUTTONPUSH,
53 CHECKBOX = DFCS_BUTTONCHECK,
54 CB3STATE = DFCS_BUTTON3STATE,
55 RADIOBUTTON = DFCS_BUTTONRADIO,
61 int m_bitmapChangeTime;
63 void m_SetCheck(
int c)
65 if ( c < 0 || c > 2 ) { c = 1; }
66 if ( m_checkState != c )
68 m_buttonBitmap.
Null();
72 if ( m_kind == RADIOBUTTON )
74 if ( c == BST_CHECKED )
76 CWnd* pParent = _super::GetParent();
80 HWND h = ::GetNextDlgGroupItem(*pParent, hWnd,
true);
81 if ( h == NULL || h == m_hWnd ) {
break; }
82 ::SendMessage(h, BM_SETCHECK, BST_UNCHECKED, 0);
85 _super::ModifyStyle(0, WS_TABSTOP);
89 _super::ModifyStyle(WS_TABSTOP, 0);
95 LONG m_originalExStyle;
126 return (m_kind == BUTTON || (m_originalStyle & BS_PUSHLIKE) != 0);
146 if ( ! m_buttonBitmap.
IsNull() )
148 m_buttonBitmap.
Draw(*pDC);
152 _super::KillTimer(TIMERID_DRAW);
153 if ( m_lastBitmap.
IsNull() || m_bitmapChangeTime == 0 )
155 m_buttonBitmap.
Draw(*pDC);
156 m_lastBitmap = m_buttonBitmap;
161 VERIFYLIB( bi.
Set(m_buttonBitmap) );
164 m_lastBitmap = m_buttonBitmap;
165 _super::SetTimer(TIMERID_DRAW, m_bitmapChangeTime, NULL);
178 dc.SetTextColor(pDC->GetTextColor());
179 CWnd* pWnd = _super::GetParent();
182 pWnd->SendMessage(WM_CTLCOLORBTN,
183 reinterpret_cast<WPARAM
>(dc.GetSafeHdc()),
reinterpret_cast<LPARAM
>(m_hWnd));
187 #ifdef DFCS_TRANSPARENT
188 uState |= DFCS_TRANSPARENT;
190 switch ( _super::GetButtonState() )
193 uState |= DFCS_PUSHED;
201 uState |= DFCS_INACTIVE;
202 if ( ! m_pDisableDraw.
IsNull() )
204 pDraw = m_pDisableDraw;
210 uState |= DFCS_FOCUS;
214 if ( m_kind == BUTTON )
216 uState |= DFCS_BUTTONPUSH;
221 if ( kind == CB3STATE && m_checkState == BST_CHECKED )
225 if ( (m_originalStyle & BS_PUSHLIKE) != 0)
227 uState |= DFCS_BUTTONPUSH;
233 if ( kind == CB3STATE )
235 if ( m_checkState == BST_INDETERMINATE )
237 uState |= DFCS_CHECKED;
240 else if ( m_checkState == BST_CHECKED )
242 uState |= DFCS_CHECKED;
246 if ( (m_originalStyle & BS_FLAT) != 0 )
252 _super::GetClientRect(rc);
262 switch( m_originalStyle & 0x0C00 )
268 r.OffsetRect(0, rc.Height() - r.bottom - l);
272 r.OffsetRect(0, (rc.Height() - r.bottom) / 2);
275 if ( (m_originalStyle & BS_LEFTTEXT) != 0 || (m_originalExStyle & WS_EX_RIGHT) != 0 )
278 r.left = rc.right - r.right;
281 rc.right -= r.Width() + 3;
287 rc.left += r.Width() + 3;
295 int y = (rc.Height() - size.cy) / 2;
298 x = (rc.Width() - size.cx) / 2;
299 if ( _super::GetButtonState() ==
ES_Pushed )
306 else if ( (m_originalExStyle & WS_EX_RIGHT) != 0 )
308 x = rc.Width() - size.cx;
310 pDraw->
Draw(dc, rc.left + x, rc.top + y);
312 if ( isPushType && m_kind == CB3STATE && m_checkState == BST_INDETERMINATE )
315 _super::GetClientRect(rc);
317 bi.
Set(rc.Width(), rc.Height());
331 rc.DeflateRect(po.x + 1, po.y + 1);
332 if ( _super::GetButtonState() ==
ES_Pushed )
343 rc.right = rc.left + size.cx;
344 rc.bottom = rc.top + size.cy;
362 if ( m_kind != RADIOBUTTON )
364 switch( m_checkState )
373 c = (m_kind == CB3STATE) ? BST_INDETERMINATE : BST_UNCHECKED;
375 case BST_INDETERMINATE:
391 m_buttonBitmap.
Null();
403 virtual LRESULT
WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
408 if ( wParam == TIMERID_DRAW )
410 KillTimer(TIMERID_DRAW);
412 m_lastBitmap.
Draw(dc);
416 if ( m_kind == RADIOBUTTON )
418 return DLGC_RADIOBUTTON | DLGC_BUTTON;
420 else if ( m_kind != BUTTON )
426 return _super::WindowProc(message, wParam, lParam) | m_checkState;
430 m_SetCheck(
ToInt(wParam));
433 if ( lParam != 0 ) { RedrawWindow(); }
436 return _super::WindowProc(message, wParam, lParam);
446 m_checkState = BST_UNCHECKED;
447 m_originalStyle = ::GetWindowLong(m_hWnd, GWL_STYLE);
448 m_originalExStyle = ::GetWindowLong(m_hWnd, GWL_EXSTYLE);
450 bool canSendDblClk = ((m_originalStyle & BS_NOTIFY) != 0);
451 switch ( m_originalStyle & BS_TYPEMASK )
453 case BS_AUTOCHECKBOX:
467 case BS_AUTORADIOBUTTON:
469 m_kind = RADIOBUTTON;
472 canSendDblClk =
true;
473 m_kind = RADIOBUTTON;
475 case BS_DEFPUSHBUTTON:
477 CWnd* P = _super::GetParent();
478 if ( P != NULL ) { P->SendMessage(DM_SETDEFID, _super::GetDlgCtrlID(), 0); }
486 _super::SetSendDblClkMode(canSendDblClk);
487 _super::PreSubclassWindow();
488 m_buttonBitmap.
Null();
507 if ( pPartsDraw != NULL )
509 m_pPartsDraw = pPartsDraw;
514 m_pPartsDraw = &s_partsDrawer;
528 m_bitmapChangeTime = ms;
537 m_pNormalDraw = draw.
Clone();
538 if ( ::IsWindow(*
this) )
540 m_buttonBitmap.
Null();
550 m_pDisableDraw = draw.
Clone();
551 if ( ::IsWindow(*
this) )
553 m_buttonBitmap.
Null();
565 if ( m_kind == BUTTON || (m_originalStyle & BS_PUSHLIKE) != 0 )
567 if ( ! m_pNormalDraw.
IsNull() )
581 case RADIOBUTTON: uState = DFCS_BUTTONRADIO;
break;
582 case CHECKBOX: uState = DFCS_BUTTONCHECK;
break;
583 case CB3STATE: uState = DFCS_BUTTON3STATE;
break;
589 _super::GetClientRect(rc);
591 SIZE size = { 0, 0 };
592 if ( ! m_pNormalDraw.
IsNull() )
596 size.cx += rc.Width() + 3;
597 size.cy = max(size.cy, rc.Height());
609 return static_cast<int>(::SendMessage(m_hWnd, BM_GETCHECK, 0, 0));
628 ::SendMessage(m_hWnd, BM_SETCHECK, nCheck, 0);
685 CFont* pFont = _super::GetFont();
688 CFont* old = pDC->SelectObject(pFont);
690 pDC->GetTextMetrics(&t);
691 pDC->SelectObject(old);
692 return t.tmHeight + t.tmExternalLeading * 2;
704 return _super::IsPushButtonStyle() ? _super::HasFocus() :
false;
714 _super::PreSubclassWindow();
716 _super::GetClientRect(&rect);
718 if ( ! _super::IsPushButtonStyle() )
723 rect.right -= r.Width() + 3;
729 _super::ReferPartsDraw()->GetEdgeOffset(po);
762 _super::SetNormalDrawer(*
m_pText);
764 _super::SetDisableDrawer(*
m_pText);
765 _super::Invalidate();
783 _super::GetWindowText(s);
786 CGdiObject* old = pDC->SelectObject(_super::GetFont());
787 CSize textSize = rc.Size();
789 pDC->SelectObject(old);
795 if ( ! _super::IsPushButtonStyle() )
803 _super::ReferPartsDraw()->GetEdgeOffset(po);
807 return _super::AdjustSize();
bool Draw(HDC hdc, int x=0, int y=0) const
[処理] イメージ描画.
bool Set(int cx, int cy, COLORREF color=CLR_INVALID)
[設定] イメージ設定.
CBitmapHandle GetBitmapHandle(void)
[取得] ビットマップハンドル取得
bool Draw(HDC hdc, int x=0, int y=0) const
[処理] イメージ描画.
bool InsertOnAlphaBlend(int x, int y, const CBitmapImage &bmpimg, int parsent=100, int cx=0, int cy=0)
[挿入] 半透過処理付イメージ挿入.
bool AlphaBlend(HDC hdc, int x, int y, int parsent=100, int cx=0, int cy=0) const
[描画] 半透明処理付イメージ描画.
bool IsNull(void) const
[確認] NULLチェック
static bool CalcTextSize(SIZE &_size, HDC dc, UINT drawStyle, LPCTSTR str)
[計算] 文字表示大きさ計算.
static DWORD ButtonToDrawStyle(DWORD buttonStyle)
[変換] ButtonスタイルをDrawTextスタイルに変換
void SetTextColor(COLORREF color)
[設定] 色設定.
void SetTextStyle(DWORD style)
[設定] スタイル設定.
CBitmapImage * Detach(void)
[設定] デタッチ.
CBitmapHandle GetParentImage(CWnd *pWndControl, COLORREF backColor=CLR_INVALID)
[取得] 親画像取得.
bool ChangeClientSize(CWnd *pWnd, int cx=-1, int cy=-1)
[設定] クライアントサイズ設定.
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).
virtual bool GetSize(SIZE &_size) const =0
[取得] サイズ取得.
virtual IDrawable * Clone(void) const =0
[作成] クローン作成.
virtual void Draw(HDC dc, int x=0, int y=0) const =0
[描画] 描画.
virtual bool DrawFocusRect(HDC hdc, LPCRECT lpRect) const =0
[描画] フォーカス枠描画.
virtual void GetEdgeOffset(POINT &_po) const =0
[取得] エッジの幅、高さ.
virtual bool DrawButtonControl(HDC hdc, LPRECT _lprc, UINT uState) const =0
[描画] ボタンコントロール描画.
virtual void GetPushedOffset(POINT &_po) const =0
[取得] 押下状態のずれ.