Here is exactly what I have written:
class CMyStatic : public CStatic
{
DECLARE_MESSAGE_MAP()
public:
void OnPaint(void);
};
BEGIN_MESSAGE_MAP(CMyStatic, CStatic)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CMyStatic::OnPaint(void)
{
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.FillSolidRect(&rect, RGB(120,255,0));
}
And subclassed:
class CMyDlg : public CDialog
{
// Construction
CMyStatic my_static;
...
};
BOOL CCMyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
my_static.SubclassDlgItem(IDC_DRAW, this);
return true;
}
Where IDC_DRAW
is static control on resource for this dialog. I wrote two button handlers:
void CMyDlg::OnBnClickedOk()
{
my_static.EnableWindow(FALSE);
my_static.Invalidate();
}
void CMyDlg::OnBnClickedOk2()
{
my_static.EnableWindow();
my_static.Invalidate();
}
And it works flawlessly! Remove Invalidate
call and it would fail.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…