更好的代码(至少对我来说):
void MyClass::OnPaint()
{
CPaintDC dc(this); // device context for painting
COLORREF highlightFillColor;
CPen nPen, *pOldPen = NULL;
CBrush nBrush, *pOldBrush = NULL;
CRect rect;
GetWindowRect(rect);
ScreenToClient(rect);
BmsMemDC memDc(&dc, &rect);
memDc.SetBkMode(TRANSPARENT);
//dc.Re
highlightFillColor = RGB(0x99,0xB4,0xFF);
nPen.CreatePen( PS_SOLID, 4, highlightFillColor);
nBrush.CreateSolidBrush( GetSysColor(COLOR_3DFACE ));
pOldPen = memDc.SelectObject(&nPen);
pOldBrush = memDc.SelectObject(&nBrush);
if(leftGroupSelected)
{
rect.SetRect(rect.left + 4, rect.top+30, rect.left + 126, rect.bottom - 5);
memDc.FillRect(&rect,&nBrush);
memDc.RoundRect(rect.left, rect.top, rect.right, rect.bottom, 8, 8);
}
if (rightGroupSelected)
{
rect.SetRect(rect.left + 134, rect.top+30, rect.left + 256, rect.bottom - 5);
memDc.FillRect(&rect,&nBrush);
memDc.RoundRect(rect.left, rect.top, rect.right, rect.bottom, 8, 8);
}
}