在子类化 CButton 时,我希望每次按下按钮时按钮的颜色都会增加。但是以下内容对背景颜色没有任何影响。但是,文本显示“c”以递增。谢谢
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++;
}
最佳答案
如果你想改变按钮的绘制方式,你应该实现CMyButton::DrawItem
(覆盖CButton::DrawItem
),并在那里进行绘制。在 OnLButtonDown
中,您只需执行如下操作:
c++;
Invalidate();
您需要 c
成为 CMyButton
的成员,而不是 OnLButtonDown
的成员。
关于c++ - CButton CDC::SetBkColor 什么都不做?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10143533/