 <p>Better code (at least for me):</p> <pre><code> 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(&amp;dc, &amp;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(&amp;nPen); pOldBrush = memDc.SelectObject(&amp;nBrush); if(leftGroupSelected) { rect.SetRect(rect.left + 4, rect.top+30, rect.left + 126, rect.bottom - 5); memDc.FillRect(&amp;rect,&amp;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(&amp;rect,&amp;nBrush); memDc.RoundRect(rect.left, rect.top, rect.right, rect.bottom, 8, 8); } </code></pre> <p>}</p>