void MyButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
CRect rc;
rc=lpDrawItemStruct->rcItem ;
COLORREF BgColor;
if(m_color_flag)
BgColor=RGB(255,0,0);
else
BgColor=RGB(0,255,0);
dc.FillSolidRect (rc,BgColor);
UINT state=lpDrawItemStruct->itemState;
if((state&ODS_SELECTED))
dc.DrawEdge (rc,EDGE_SUNKEN, BF_RECT);
else
dc.DrawEdge (rc, EDGE_RAISED, BF_RECT);
dc.SetTextColor(RGB(0,0,0));
CString temp;
GetWindowText(temp);
dc.DrawText(temp,rc,
DT_CENTER|DT_VCENTER|DT_SINGLELINE);
if((state&ODS_FOCUS))
{
int ichange=2;
rc.bottom-=ichange;
rc.top+=ichange;
rc.left+=ichange;
rc.right-=ichange;
dc.DrawFocusRect(rc);
}
dc.Detach();
}
void MyButton::OnClicked()
{
// TODO: Add your control notification handler
code here
if(m_color_flag)
m_color_flag=false;
Invalidate(); //Redraw the button immediately
}
Please advise,
Yitche
>.
>