// Paint the background of the progress bar region void ProgressBar::paintBackground( CDC &dc ) { CBrush brshBackground; CPen penGray( PS_SOLID, 1, RGB (128, 128, 128) ); CPen penWhite( PS_SOLID, 1, RGB (255, 255, 255) ); VERIFY( brshBackground.CreateSolidBrush( ::GetSysColor (COLOR_BTNFACE) ) ); dc.FillRect( m_bounds, &brshBackground ); CPen *pOldPen = dc.SelectObject( &penGray ); int xRight = m_bounds.left + m_bounds.Width() -1; int yBottom = m_bounds.top + m_bounds.Height() -1; { dc.MoveTo( m_bounds.left, m_bounds.top ); dc.LineTo( xRight, m_bounds.top ); dc.MoveTo( m_bounds.left, m_bounds.top ); dc.LineTo( m_bounds.left, yBottom ); } dc.SelectObject( &penWhite ); { dc.MoveTo( xRight, m_bounds.top ); dc.LineTo( xRight, yBottom ); dc.MoveTo( m_bounds.left, yBottom ); dc.LineTo( xRight, yBottom ); } dc.SelectObject( pOldPen ); }
void CDockingBar::OnPaint() { CPaintDC dc(this); // device context for painting COLORREF rgb_background= ::GetSysColor(COLOR_APPWORKSPACE); CMemoryDC mem_dc(dc, this, rgb_background); mem_dc.SelectStockObject(DEFAULT_GUI_FONT); CRect rect; GetClientRect(rect); mem_dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DSHADOW), ::GetSysColor(COLOR_3DHILIGHT)); rect.DeflateRect(1, 1); mem_dc.Draw3dRect(rect, ::GetSysColor(COLOR_3DDKSHADOW), rgb_background); rect.DeflateRect(1, 0); rect.top++; const int GAP= rect.Height() / 2; const int ICON= 18; COLORREF rgb_black= ::GetSysColor(COLOR_BTNTEXT); COLORREF rgb_dark= ::GetSysColor(COLOR_3DDKSHADOW); COLORREF rgb_light= ::GetSysColor(COLOR_3DHILIGHT); COLORREF rgb_gray= GetLighterColor(rgb_background, 13.0); // 13.0% brighter CPen penBlack(PS_SOLID, 0, rgb_black); CPen penDark(PS_SOLID, 0, rgb_dark); CPen penLight(PS_SOLID, 0, rgb_light); CPen penGray(PS_SOLID, 0, rgb_gray); CBrush brGray(::GetSysColor(COLOR_3DFACE)); CBrush* brush= mem_dc.SelectObject(&brGray); mem_dc.SetBkMode(OPAQUE); CalcWidth(tabs_, mem_dc, rect); for (int index= 0; index < tabs_.size(); ++index) { CTab& tab= tabs_[index]; CRect text_rect= tab.location_rect_; text_rect.left += ICON; COLORREF rgb_tab= tab.active_ ? ::GetSysColor(COLOR_3DFACE) : rgb_background; if (tab.active_) // active tab--taller, gray backgnd { CRect rect= tab.location_rect_; rect.top++; rect.right++; rect.bottom = rect.top + 1; // draw two lines on the top mem_dc.FillSolidRect(rect, rgb_dark); rect.OffsetRect(0, 1); mem_dc.FillSolidRect(rect, rgb_light); rect.top++; rect.bottom = tab.location_rect_.bottom + 1; mem_dc.FillSolidRect(rect, rgb_tab); text_rect.top = rect.top; rect.top--; int bottom= tab.location_rect_.bottom - 1; int gap= (bottom - rect.top) / 2; POINT vptLeftTriangle[]= { { rect.left, rect.top }, { rect.left, bottom + 2 }, { rect.left - gap - 1, bottom + 2 }, { rect.left, rect.top } }; mem_dc.SelectStockObject(NULL_PEN); mem_dc.Polygon(vptLeftTriangle, array_count(vptLeftTriangle)); POINT vptRightTriangle[]= { { rect.right, rect.top }, { rect.right, bottom + 2 }, { rect.right + gap, bottom + 2 }, { rect.right + gap, bottom }, { rect.right, rect.top } }; mem_dc.Polygon(vptRightTriangle, array_count(vptRightTriangle)); // draw slanted line on the right side CPen* pen= mem_dc.SelectObject(&penBlack); mem_dc.MoveTo(rect.right, rect.top); mem_dc.LineTo(rect.right + gap, bottom); mem_dc.LineTo(rect.right + gap + 1, bottom); // draw slanted line on the left side mem_dc.SelectObject(&penDark); int left= rect.left - 1; mem_dc.MoveTo(left, rect.top); mem_dc.LineTo(left - gap, bottom); mem_dc.LineTo(left - gap + 1, bottom); // draw light slanted line on the left side mem_dc.SelectObject(&penLight); left++; mem_dc.MoveTo(left, rect.top); mem_dc.LineTo(left - gap, bottom); mem_dc.LineTo(left - gap, bottom + 2); } else // inactive tab (smaller, dark background) { CRect rect= tab.location_rect_; rect.left++; rect.right++; rect.top += 2; rect.bottom = rect.top + 1; // draw two lines on the top mem_dc.FillSolidRect(rect, rgb_dark); rect.OffsetRect(0, 1); mem_dc.FillSolidRect(rect, rgb_gray); // draw slanted line on the right side CPen* pen= mem_dc.SelectObject(&penBlack); int right= rect.right - 0; mem_dc.MoveTo(right, rect.top); int bottom= tab.location_rect_.bottom - 1; int gap= (bottom - rect.top) / 2; mem_dc.LineTo(right + gap, bottom + 1); // draw short slanted line on the left side mem_dc.SelectObject(&penDark); int left= rect.left - 1; mem_dc.MoveTo(left, rect.top); if (index == 0) // first tab? { mem_dc.LineTo(left - gap, bottom); // in the first tab whole edge is visible mem_dc.LineTo(left - gap, bottom + 1); // draw light slanted line on the left side mem_dc.SelectObject(&penGray); mem_dc.MoveTo(left + 1, rect.top); mem_dc.LineTo(left - gap + 1, bottom); mem_dc.LineTo(left - gap + 1, bottom + 1); } else { int left_half= left - gap / 2; int bottom_half= (rect.top + bottom) / 2; mem_dc.LineTo(left_half, bottom_half); mem_dc.LineTo(left_half, bottom_half + 1); // draw light slanted line on the left side mem_dc.SelectObject(&penGray); mem_dc.MoveTo(left + 1, rect.top); mem_dc.LineTo(left_half, bottom_half + 2); // previous tab is not active? // if (index > 0 && !tabs_[index - 1].active_) // mem_dc.LineTo(left_half, bottom_half + 3); } mem_dc.SelectObject(pen); text_rect.top = rect.top + 1; } mem_dc.SetBkColor(rgb_tab); mem_dc.DrawText(tab.name_, text_rect, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX | DT_EXPANDTABS | DT_END_ELLIPSIS); int offset= tab.active_ ? 0 : 12; CPoint icon(tab.location_rect_.left + 1, text_rect.top); if (tab.icon_ >= 0) image_list_.Draw(&mem_dc, offset + tab.icon_, icon, ILD_NORMAL); } mem_dc.SelectObject(brush); mem_dc.BitBlt(); }