Reputation: 2385
I have a function that checks whenever a button check box i clicked
void CRisanjeDlg::OnBnClickedCheck1()
{
Invalidate(1);
}
And in the OnPaint method i have this code:
if(m_CheckBox1.GetState() ==1 )
{
CBrush brush;
CRect rect;
GetClientRect(rect);
brush.CreateSolidBrush(RGB(255,200,255));
rect.DeflateRect(0,0,500,0);
dc.Rectangle(rect);
dc.FillRect(rect, &brush);
}
I have a couple of other events, which trigger the OnPaint method, and if the box is checked, it draws what it has to draw.
It just doesn't work when i click the check box. The event is recognized, it's just that the Invalidate(1) does not work...
Any suggestions?
EDIT: When I uncheck the box, the function works fine. It seems the problem should be in the
if(m_CheckBox1.GetState() ==1 )
part.
EDIT2: True, the problem was in the mentioned if statement. This fixed it, don't know why. Would appreciate a further explanation.
m_CheckBox1.GetCheck() ==1
Upvotes: 0
Views: 666
Reputation: 308206
GetState
returns a combination of states. Since the user is pressing on the button, you'll have BST_PUSHED
and BST_FOCUS
in addition to BST_CHECKED
. It would have worked if you just tested for the single bit:
if ((m_CheckBox1.GetState() & BST_CHECKED) == BST_CHECKED)
Which can be simplified, since any non-zero value is true:
if (m_CheckBox1.GetState() & BST_CHECKED)
Upvotes: 1
Reputation: 1817
Try to use the debugger and see if you are coming inside your OnBnClickedCheck1 function
Upvotes: 1