On subclassing CButton, I want the color of the button to increment each time the button is pressed. But the following is doing nothing to the background color. However, the text shows “c” to increment. thx
void CMyButton::OnLButtonDown(UINT nFlags, CPoint point)
{
CButton::OnLButtonDown(nFlags, point);
static int c;
CString s;
s.Format("left: %d", c*50);
this->SetWindowText(s);
////// Neither of the following change the background color
//CPaintDC dc(this);
//dc.SetBkColor(0x0 + c*50);
CDC *dc= GetDC();
dc->SetBkColor(0x0 + c*50);
c++;
}
If you want to change how your button is drawn, you should implement
CMyButton::DrawItem(overridingCButton::DrawItem), and do the drawing there. InOnLButtonDown, you’ll just do something like:You’ll want
cto be a member ofCMyButton, not local toOnLButtonDown.