void CButtonEx::DrawItem(LPDRAWITEMSTRUCT lpDS)
{
// TODO: Add your code to draw the specified item
CRect rect = lpDS->rcItem;
CDC *pDC = CDC::FromHandle(lpDS->hDC);
pDC->SelectStockObject(GRAY_BRUSH);
pDC->FillSolidRect(rect,GetSysColor(COLOR_BTNFACE));
if ((lpDS->itemState&ODS_SELECTED))//选中的时候
{
pDC->DrawEdge(rect,BDR_SUNKENINNER|BDR_SUNKENOUTER,BF_RECT);
rect.OffsetRect(1,1);
}
else //没有选中的时候
{
pDC->DrawEdge(rect,BDR_RAISEDINNER,BF_RECT);
}
int n = rect.Height();
n = (n-16)/2;
if ((lpDS->itemState&ODS_SELECTED))//选中的时候
n+=2;
DrawIconEx(lpDS->hDC,n,n,m_hIcon,16,16,0,0,DI_NORMAL);
CString strCaption;
GetWindowText(strCaption);//获取按钮文本
// pDC->SetBkMode(TRANSPARENT);
CRect rc(rect);
rc.left = n;
pDC->DrawText(strCaption, rc, DT_CENTER | DT_VCENTER | DT_SINGLELINE);//重绘按钮文本
if (lpDS->itemState&ODS_FOCUS)//获得焦点的时候
{
rect.DeflateRect(2,2);
pDC->DrawFocusRect(rect);
}
}