16 #error not support "PressButton"
29 #define BN_PUSHED BN_HILITE
32 #define BN_UNPUSHED BN_UNHILITE
60 void PostCommand(UINT uCmd)
70 virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam)
72 return _super::OnCommand(wParam, lParam);
84 virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
86 if ( message == WM_LBUTTONDOWN )
92 PostCommand(BN_PUSHED);
96 else if ( message == WM_LBUTTONUP )
100 m_boIsPushed =
false;
102 PostCommand(BN_UNPUSHED);
103 PostCommand(BN_CLICKED);
107 else if ( message == WM_LBUTTONDBLCLK )
109 if ( ! m_boIsPushed )
111 PostCommand(BN_PUSHED);
113 m_boIsPushed =
false;
115 PostCommand(BN_UNPUSHED);
116 PostCommand(BN_DOUBLECLICKED);
119 else if ( message == WM_SETFOCUS || message == WM_KILLFOCUS )
123 return _super::WindowProc(message, wParam, lParam);
131 virtual void PreSubclassWindow(
void)
133 UINT uiDefBtnSte = _super::GetButtonStyle() & 0xFF;
134 if ( uiDefBtnSte == BS_PUSHBUTTON || uiDefBtnSte == BS_DEFPUSHBUTTON )
136 _super::SetButtonStyle(BS_AUTOCHECKBOX);
137 _super::ModifyStyle(0, BS_OWNERDRAW);
139 _super::PreSubclassWindow();
148 virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
150 if ( lpDrawItemStruct->CtlType != ODT_BUTTON || lpDrawItemStruct->hwndItem != _super::GetSafeHwnd() )
154 CDC *dc = CDC::FromHandle(lpDrawItemStruct->hDC);
156 UINT uItemState = lpDrawItemStruct->itemState;
159 UINT uState = DFCS_BUTTONPUSH | 0x0800;
162 uState |= DFCS_PUSHED;
164 dc->DrawFrameControl(&(lpDrawItemStruct->rcItem), DFC_BUTTON, uState);
166 if (
ToInt(m_colorBack) >= 0 )
168 CRect cRect = lpDrawItemStruct->rcItem;
169 cRect.DeflateRect(2, 2, 2, 2);
170 dc->FillSolidRect(cRect, m_colorBack);
174 GetWindowText(strText);
175 if ( ! strText.IsEmpty() )
177 CRect cRect = lpDrawItemStruct->rcItem;
178 cRect.DeflateRect(4, 4, 4, 4);
181 cRect.OffsetRect(1, 1);
183 dc->SetBkMode(TRANSPARENT);
184 if ( (uItemState & ODS_DISABLED) != 0 )
186 dc->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
188 dc->DrawText(strText, cRect, DT_CENTER | DT_VCENTER);
208 : m_colorBack(COLORREF(-1))
209 , m_boIsPushed(false)
238 PostMessage(WM_LBUTTONDOWN);
246 PostMessage(WM_LBUTTONUP);
LRESULT SendCommandMessage(CWnd *pCtrl, UINT cmd)
[処理] WM_COMMAND送信.
int ToInt(LPCSTR lpsz, int iBase=10)
[変換] INT変換(ASCII/SJIS用).