Exemple #1
0
void CColorButtonCtrl::DrawBevelInset(CDC* pDC, CRect& rc)
{
    CPen penLight(PS_SOLID, 1, ::GetSysColor(COLOR_3DHILIGHT));
    CPen penShadow(PS_SOLID, 1, ::GetSysColor(COLOR_3DSHADOW));

    DrawBevel(pDC, rc, penShadow, penLight);
}
void CColorPaletteButton::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CButton::OnPaint() for painting messages
   COLORREF buttonColor = (m_appPalette.isPaletteDevice() ? 
      PALETTEINDEX(m_appPalette.getEditIndex()) : 
      m_appPalette.getEditColor() );

   TRACE("CColorPaletteButton::OnPaint() - buttonColor = %08x\n",buttonColor);

   CRect rect;
   GetClientRect(&rect);
   CPen penHighlight(PS_SOLID,1,GetSysColor(COLOR_BTNHIGHLIGHT));
   CPen* oldPen = dc.SelectObject(&penHighlight);
   dc.MoveTo(rect.left,rect.bottom);
   dc.LineTo(rect.right,rect.bottom);
   dc.LineTo(rect.right,rect.top - 1);

   CPen penShadow(PS_SOLID,1,GetSysColor(COLOR_BTNSHADOW));
   dc.SelectObject(&penShadow);
   dc.MoveTo(rect.left,rect.bottom - 1);
   dc.LineTo(rect.left,rect.top);
   dc.LineTo(rect.right,rect.top);

   CPen penFace(PS_SOLID,1,GetSysColor(COLOR_BTNFACE));
   dc.SelectObject(&penFace);
   dc.MoveTo(rect.left + 1,rect.bottom - 1);
   dc.LineTo(rect.right - 1,rect.bottom - 1);
   dc.LineTo(rect.right - 1,rect.top);

   CPen penDarkShadow(PS_SOLID,1,GetSysColor(COLOR_3DDKSHADOW));
   dc.SelectObject(&penDarkShadow);
   dc.MoveTo(rect.left + 1,rect.bottom - 2);
   dc.LineTo(rect.left + 1,rect.top + 1);
   dc.LineTo(rect.right - 1,rect.top + 1);

   dc.SelectObject(oldPen);

   m_appPalette.pushPalette(&dc);

   CBrush brush;
   brush.CreateSolidBrush(buttonColor);
   CBrush* oldBrush = dc.SelectObject(&brush);
   rect.top += 2;
   rect.left += 2;
   rect.bottom -= 1;
   rect.right -= 1;
   dc.SelectObject(&brush);
   dc.FillRect(&rect,&brush);

   dc.SelectObject(oldBrush);

   m_appPalette.popPalette(&dc);
}
Exemple #3
0
void CCJToolBar::Draw3dRect(CDC *pDC, CRect rc) const
{
	static bool bDraw2nd = true;

	if (bDraw2nd == true) {
		rc.right  -= 1;
		rc.bottom -= 1;
	}

	// Get a pen for hilite and shadow.
	CPen penHilite(PS_SOLID, 1, ::GetSysColor(COLOR_BTNHILIGHT));
	CPen penShadow(PS_SOLID, 1, ::GetSysColor(COLOR_BTNSHADOW));

	// Set up points for line draw.
	CPoint ptTopLeft	(rc.left,  rc.top);
	CPoint ptTopRight	(rc.right, rc.top);
	CPoint ptBottomLeft	(rc.left,  rc.bottom);
	CPoint ptBottomRight(rc.right, rc.bottom);

	// Select the shadow pen, and draw the bottom right.
	pDC->SelectObject(&penShadow);

	pDC->MoveTo(ptTopRight);
	pDC->LineTo(ptBottomRight);
	pDC->LineTo(ptBottomLeft);

	// Select the hilite pen, and draw the top left.
	pDC->SelectObject(&penHilite);

	pDC->MoveTo(ptBottomLeft);
	pDC->LineTo(ptTopLeft);
	pDC->LineTo(ptTopRight);

	// Draw the second gripper line.
	if (bDraw2nd == true)
	{
		bDraw2nd = false;
		if (m_dwStyle & CBRS_ORIENT_HORZ)
			rc.OffsetRect(3,0);
		else 
			rc.OffsetRect(0,3);
		Draw3dRect(pDC, rc);
		bDraw2nd = true;
	}
}
Exemple #4
0
/*******************************************************************************
  Function Name  : DrawItem
  Input(s)       : LPDRAWITEMSTRUCT
  Output         : -
  Functionality  : overrided for drawing the Arrow direction for sort in
                   Column header field.
  Member of      : CListHdrCtrl
  Author(s)      : Arunkumar K
  Date Created   : 20-05-2010
  Modifications  :
*******************************************************************************/
void CRxMsgList::CListHdrCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    //Attach the column header HDC.
    CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);
    // save device context.
    const int nSavedDCState = dc.SaveDC();
    // get the column rect.
    CRect rc(lpDrawItemStruct->rcItem);
    // set the clipping region to limit drawing within the column.
    CRgn rgn;
    rgn.CreateRectRgnIndirect(&rc);
    dc.SelectObject(&rgn);
    rgn.DeleteObject();
    // draw the background,
    CBrush brush(GetSysColor(COLOR_3DFACE));
    dc.FillRect(rc, &brush);
    // get the column text and format.
    char szText[ 256 ];
    HD_ITEM hditem;
    hditem.mask = HDI_TEXT | HDI_FORMAT;
    hditem.pszText = szText;
    hditem.cchTextMax = 255;
    GetItem(lpDrawItemStruct->itemID, &hditem);
    // determine the format for drawing the column label.
    UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;

    if(hditem.fmt & HDF_CENTER)
    {
        uFormat |= DT_CENTER;
    }
    else if(hditem.fmt & HDF_RIGHT)
    {
        uFormat |= DT_RIGHT;
    }
    else
    {
        uFormat |= DT_LEFT;
    }

    // adjust the rect if the mouse button is pressed on it.
    if(lpDrawItemStruct->itemState == ODS_SELECTED)
    {
        rc.left++;
        rc.top += 2;
        rc.right++;
    }

    CRect rcIcon(lpDrawItemStruct->rcItem);
    const int nOffset = (rcIcon.bottom - rcIcon.top) / 4;

    // adjust the rect further if the sort arrow is to be displayed.
    if(lpDrawItemStruct->itemID == (UINT)m_nSortCol)
    {
        rc.right -= 3 * nOffset;
    }

    rc.left += nOffset;
    rc.right -= nOffset;

    // draw the column label.
    if(rc.left < rc.right)
    {
        dc.DrawText(szText, -1, rc, uFormat);
    }

    // draw the sort arrow.
    if(lpDrawItemStruct->itemID == (UINT)m_nSortCol)
    {
        // set up the pens to use for drawing the arrow.
        CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
        CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
        CPen* pOldPen = dc.SelectObject(&penLight);
        CDC dcMem;
        BITMAP bm;
        CBitmap bmpArrowDir;
        COLORMAP cm = {RGB(0, 0, 0), GetSysColor(COLOR_BTNTEXT)};
        dcMem.CreateCompatibleDC(&dc);

        if(m_bIsAscendingSort)
        {
            bmpArrowDir.LoadMappedBitmap(IDB_HDRUP, 0, &cm, 1);
            bmpArrowDir.GetBitmap(&bm);
            dcMem.SelectObject(&bmpArrowDir);
            dc.SetStretchBltMode(HALFTONE);
            dc.SetBkMode(TRANSPARENT);
            dc.StretchBlt(rcIcon.right-15, rcIcon.top+5, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND);
        }
        else
        {
            bmpArrowDir.LoadMappedBitmap(IDB_HDRDOWN, 0, &cm, 1);
            bmpArrowDir.GetBitmap(&bm);
            dcMem.SelectObject(&bmpArrowDir);
            dc.SetStretchBltMode(HALFTONE);
            dc.SetBkMode(TRANSPARENT);
            dc.StretchBlt(rcIcon.right-15, rcIcon.top+5, bm.bmWidth, bm.bmHeight, &dcMem, 0, 0, bm.bmWidth, bm.bmHeight, SRCAND);
        }

        bmpArrowDir.DeleteObject();
        // restore the pen.
        dc.SelectObject(pOldPen);
    }

    // restore the stored device context state.
    dc.RestoreDC(nSavedDCState);
    // detach the HDC before exit.
    dc.Detach();
}
Exemple #5
0
void CNavPaneWnd::DrawTab(CDC* pDC, int nTab, bool bActive)
{
	Tab& tab = m_tabs[nTab];

	COLORREF clrBtnface = ::GetSysColor(COLOR_BTNFACE);
	COLORREF clrTabBg = ChangeBrightness(clrBtnface, 0.85);
	COLORREF clrHilight = ::GetSysColor(COLOR_BTNHILIGHT);
	COLORREF clrShadow = ::GetSysColor(COLOR_BTNSHADOW);
	COLORREF clrFrame = ::GetSysColor(COLOR_WINDOWFRAME);
	COLORREF clrText = ::GetSysColor(COLOR_WINDOWTEXT);

	CBrush brushBtnface(clrBtnface);
	CPen penBtnface(PS_SOLID, 1, clrBtnface);
	CPen penShadow(PS_SOLID, 1, clrShadow);
	CPen penHilight(PS_SOLID, 1, clrHilight);

	CRect rcTab = tab.rcTab;
	rcTab.bottom += s_nTabSize / 2 - 2;
	pDC->FillSolidRect(rcTab, clrBtnface);

	// Vertical line
	CRect rcLine(rcTab.left, rcTab.top, rcTab.left + 1, rcTab.bottom);
	pDC->FillSolidRect(rcLine, clrShadow);

	// Horizontal line
	CRect rcHorzLine(rcTab.left, rcTab.bottom, rcTab.right, rcTab.bottom + 1);
	pDC->FillSolidRect(rcHorzLine, clrShadow);

	CPoint points[] = {
			CPoint(rcTab.left, rcTab.top - 1),
			CPoint(rcTab.right - 1, rcTab.top - s_nTabSize + 1),
			CPoint(rcTab.right - 1, rcTab.top - 1) };

	CBrush* pOldBrush = pDC->SelectObject(&brushBtnface);
	CPen* pOldPen = pDC->SelectObject(&penBtnface);
	pDC->SetPolyFillMode(WINDING);
	pDC->Polygon(points, 3);
	pDC->SelectObject(pOldBrush);
	pDC->SelectObject(pOldPen);

	CPoint points2[] = {
			CPoint(rcTab.left, rcTab.top - 1),
			CPoint(rcTab.right + 1, rcTab.top - s_nTabSize - 1) };

	pOldPen = pDC->SelectObject(&penShadow);
	pDC->Polyline(points2, 2);
	pDC->SelectObject(pOldPen);

	if (bActive)
	{
		rcLine.OffsetRect(s_nTabSize - 1, 0);
		rcLine.top -= s_nTabSize - 1;
		pDC->FillSolidRect(rcLine, clrBtnface);
	}

	CFont* pOldFont = pDC->SelectObject(bActive ? &m_fontActive : &m_font);
	pDC->SetTextColor(clrText);
	pDC->SetBkMode(TRANSPARENT);
	pDC->SetTextAlign(TA_CENTER | TA_BASELINE);
	pDC->TextOut(tab.rcTab.right - 4, tab.rcTab.CenterPoint().y, tab.strName);
	pDC->SelectObject(pOldFont);
}
void CMyHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC dc;
	VERIFY( dc.Attach( lpDrawItemStruct->hDC ) );
	const int iSavedDC = dc.SaveDC();
	CRect rc( lpDrawItemStruct->rcItem );
	CRgn rgn;
	VERIFY( rgn.CreateRectRgnIndirect( &rc ) );
	(void)dc.SelectObject( &rgn );
	VERIFY( rgn.DeleteObject() );
	CBrush brush( GetSysColor( COLOR_3DFACE ) );
	dc.SetBkMode(TRANSPARENT);
		int r1=GetRValue(m_clrBack);
		int g1=GetGValue(m_clrBack);
		int b1=GetBValue(m_clrBack);
		for(int i=rc.Height()/2;i>0;i--)
		{
			r1=(r1+5)>255?255:(r1+5);
			g1=(g1+5)>255?255:(g1+5);
			b1=(b1+5)>255?255:(b1+5);
			CPen pen(PS_SOLID, 1, RGB(r1, g1, b1));
			CPen *old = dc.SelectObject(&pen);
			dc.MoveTo(rc.left,rc.top+i);
			dc.LineTo(rc.right,rc.top+i);
			dc.MoveTo(rc.left,rc.bottom-i);
			dc.LineTo(rc.right,rc.bottom-i);
			dc.SelectObject(old);
		}	
	TCHAR szText[ 256 ];
	HD_ITEM hditem;
	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = szText;
	hditem.cchTextMax = 255;
	VERIFY( GetItem( lpDrawItemStruct->itemID, &hditem ) );
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;
	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rc.left++;
		rc.top += 2;
		rc.right++;
	}
	CRect rcIcon( lpDrawItemStruct->rcItem );
	const int iOffset = ( rcIcon.bottom - rcIcon.top ) / 4;
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
		rc.right -= 3 * iOffset;

	rc.left += iOffset;
	rc.right -= iOffset;
	if( rc.left < rc.right )
		(void)dc.DrawText( szText, -1, rc, uFormat );
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
	{
		CPen penLight( PS_SOLID, 1,m_clrLeft);
		CPen penShadow( PS_SOLID, 1,m_clrRight);
		CPen* pOldPen = dc.SelectObject( &penLight );
		if( m_bSortAscending )
		{
			dc.MoveTo( rcIcon.right - 2 * iOffset, iOffset);
			dc.LineTo( rcIcon.right - iOffset, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 3 * iOffset - 2, rcIcon.bottom - iOffset - 1 );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 3 * iOffset - 1, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 2 * iOffset, iOffset - 1);		
		}
		else
		{
			dc.MoveTo( rcIcon.right - iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - 2 * iOffset - 1, rcIcon.bottom - iOffset );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 2 * iOffset - 2, rcIcon.bottom - iOffset );
			dc.LineTo( rcIcon.right - 3 * iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - iOffset - 1, iOffset );		
		}
		(void)dc.SelectObject( pOldPen );
	}
	VERIFY( dc.RestoreDC( iSavedDC ) );
	(void)dc.Detach();
}
void CSortHeaderCtrl::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	// attath to the device context.
	CDC dc;
	VERIFY( dc.Attach( lpDrawItemStruct->hDC ) );

	// save the device context.
	const int iSavedDC = dc.SaveDC();

	// get the column rect.
	CRect rc( lpDrawItemStruct->rcItem );

	// set the clipping region to limit drawing within the column.
	CRgn rgn;
	VERIFY( rgn.CreateRectRgnIndirect( &rc ) );
	(void)dc.SelectObject( &rgn );
	VERIFY( rgn.DeleteObject() );

	// draw the background,
	CBrush brush( GetSysColor( COLOR_3DFACE ) );
	dc.FillRect( rc, &brush );

	// get the column text and format.
	TCHAR szText[ 256 ];
	HD_ITEM hditem;

	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = szText;
	hditem.cchTextMax = 255;

	VERIFY( GetItem( lpDrawItemStruct->itemID, &hditem ) );

	// determine the format for drawing the column label.
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | DT_VCENTER | DT_END_ELLIPSIS ;

	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;

	// adjust the rect if the mouse button is pressed on it.
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rc.left++;
		rc.top += 2;
		rc.right++;
	}

	CRect rcIcon( lpDrawItemStruct->rcItem );
	const int iOffset = ( rcIcon.bottom - rcIcon.top ) / 4;

	// adjust the rect further if the sort arrow is to be displayed.
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
		rc.right -= 3 * iOffset;

	rc.left += iOffset;
	rc.right -= iOffset;

	// draw the column label.
	if( rc.left < rc.right )
		(void)dc.DrawText( szText, -1, rc, uFormat );

	// draw the sort arrow.
	if( lpDrawItemStruct->itemID == (UINT)m_iSortColumn )
	{
		// set up the pens to use for drawing the arrow.
		CPen penLight( PS_SOLID, 1, GetSysColor( COLOR_3DHILIGHT ) );
		CPen penShadow( PS_SOLID, 1, GetSysColor( COLOR_3DSHADOW ) );
		CPen* pOldPen = dc.SelectObject( &penLight );

		if( m_bSortAscending )
		{
			// draw the arrow pointing upwards.
			dc.MoveTo( rcIcon.right - 2 * iOffset, iOffset);
			dc.LineTo( rcIcon.right - iOffset, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 3 * iOffset - 2, rcIcon.bottom - iOffset - 1 );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 3 * iOffset - 1, rcIcon.bottom - iOffset - 1 );
			dc.LineTo( rcIcon.right - 2 * iOffset, iOffset - 1);		
		}
		else
		{
			// draw the arrow pointing downwards.
			dc.MoveTo( rcIcon.right - iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - 2 * iOffset - 1, rcIcon.bottom - iOffset );
			(void)dc.SelectObject( &penShadow );
			dc.MoveTo( rcIcon.right - 2 * iOffset - 2, rcIcon.bottom - iOffset );
			dc.LineTo( rcIcon.right - 3 * iOffset - 1, iOffset );
			dc.LineTo( rcIcon.right - iOffset - 1, iOffset );		
		}

		// restore the pen.
		(void)dc.SelectObject( pOldPen );
	}

	// restore the previous device context.
	VERIFY( dc.RestoreDC( iSavedDC ) );

	// detach the device context before returning.
	(void)dc.Detach();
}
void COXGridHeader::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	if (m_UxTheme.IsUxThemeLoaded())
	{
		HTHEME hTheme = m_UxTheme.GetWindowTheme(m_hWnd);
		if (hTheme != NULL)
		{

			// Draw the item background
			int iState = HIS_NORMAL;
			if (lpDrawItemStruct->itemState == ODS_SELECTED)
				iState = HIS_PRESSED;
			else
			{
				POINT ptCursor;
				::GetCursorPos(&ptCursor);
				ScreenToClient(&ptCursor);
				CRect rectItem(lpDrawItemStruct->rcItem);
				if (rectItem.PtInRect(ptCursor))
					iState = HIS_HOT;
			}
			m_UxTheme.DrawThemeBackground(hTheme,
				lpDrawItemStruct->hDC,
				HP_HEADERITEM,
				iState,
				&lpDrawItemStruct->rcItem,
				NULL);

			BOOL bDrawArrow;
			if (m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol)
				bDrawArrow = TRUE;
			else
				bDrawArrow = FALSE;


			// Get the column text and format	
			TCHAR buf[256];	
			HD_ITEM hditem;	
			hditem.mask = HDI_TEXT | HDI_FORMAT;	
			hditem.pszText = buf;
			hditem.cchTextMax = 255;	
			GetItem( lpDrawItemStruct->itemID, &hditem );

			RECT rectText = lpDrawItemStruct->rcItem;
			rectText.left += 9;
			rectText.right -= 9;

			// Determine format for drawing column label
			UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | 
				DT_VCENTER | DT_END_ELLIPSIS ;
			UINT uArrowFormat = DT_SINGLELINE | DT_VCENTER;
			if( hditem.fmt & HDF_CENTER)
			{
				uFormat |= DT_CENTER;
				uArrowFormat |= DT_RIGHT;
				if (bDrawArrow)
					rectText.right -= 12;
			}
			else if( hditem.fmt & HDF_RIGHT)
			{
				uFormat |= DT_RIGHT;
				uArrowFormat |= DT_LEFT;
				if (bDrawArrow)
					rectText.left += 12;
			}
			else
			{
				uFormat |= DT_LEFT;
				uArrowFormat |= DT_RIGHT;
				if (bDrawArrow)
					rectText.right -= 12;
			}

			m_UxTheme.DrawThemeText(hTheme,
				lpDrawItemStruct->hDC,
				HP_HEADERITEM,
				HIS_NORMAL,
				buf,
				-1,
				uFormat,
				0,
				&rectText);

			// Draw the Sort arrow	
			if (bDrawArrow)	
			{
				CDC dc;
				dc.Attach(lpDrawItemStruct->hDC);
				int nSavedDC = dc.SaveDC();
				CFont fontMarlett;
				fontMarlett.CreatePointFont(120, _T("Marlett"));
				dc.SelectObject(&fontMarlett);
				dc.SetBkMode(TRANSPARENT);
				dc.SetTextColor(RGB(128, 128, 128));

				CRect rectArrow = lpDrawItemStruct->rcItem;
				rectArrow.DeflateRect(5, 0, 5, 0);

				if (m_nSortOrder == 1)
					dc.DrawText(_T("5"), -1, &rectArrow, uArrowFormat);
				else
					dc.DrawText(_T("6"), -1, &rectArrow, uArrowFormat);

				// Restore dc	
				dc.RestoreDC(nSavedDC);
				// Detach the dc before returning	
				dc.Detach();
			}
			return;
		}
	}

	CDC dc;
	dc.Attach( lpDrawItemStruct->hDC );	
	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );	
	// Save DC
	int nSavedDC = dc.SaveDC();
	// Set clipping region to limit drawing within column	
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );	
	dc.SelectObject( &rgn );
	rgn.DeleteObject(); 
	// Draw the background
	CBrush brush(::GetSysColor(COLOR_3DFACE));
	dc.FillRect(rcLabel,&brush);	
	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = dc.GetTextExtent(_T(" "), 1 ).cx*2;
	// Get the column text and format	
	TCHAR buf[256];	
	HD_ITEM hditem;	
	hditem.mask = HDI_TEXT | HDI_FORMAT;	
	hditem.pszText = buf;
	hditem.cchTextMax = 255;	
	GetItem( lpDrawItemStruct->itemID, &hditem );
	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP | 
		DT_VCENTER | DT_END_ELLIPSIS ;	
	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;	
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;
	// Adjust the rect if the mouse button is pressed on it
	if( lpDrawItemStruct->itemState == ODS_SELECTED )	
	{		
		rcLabel.left++;
		rcLabel.top += 2;		
		rcLabel.right++;	
	}
	// Adjust the rect further if Sort arrow is to be displayed
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )	
	{
		rcLabel.right -= 3 * offset;	
	}
	rcLabel.left += offset;
	rcLabel.right -= offset;	
	// Draw column label
	if( rcLabel.left < rcLabel.right )
		dc.DrawText(buf,-1,rcLabel, uFormat);
	// Draw the Sort arrow	
	if( m_nSortOrder!=0 && lpDrawItemStruct->itemID == (UINT)m_nSortCol )	
	{
		CRect rcIcon( lpDrawItemStruct->rcItem );
		// Set up pens to use for drawing the triangle
		CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
		CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = dc.SelectObject( &penLight );		
		if( m_nSortOrder==1 )		
		{
			// Draw triangle pointing upwards
			dc.MoveTo( rcIcon.right - 2*offset, offset-1);
			dc.LineTo( rcIcon.right - 3*offset/2, rcIcon.bottom - offset );
			dc.LineTo( rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset );
			dc.MoveTo( rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1 );
			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 2*offset, offset-2);		
		}
		else		
		{
			// Draw triangle pointing downwords
			dc.MoveTo( rcIcon.right - 3*offset/2, offset-1);
			dc.LineTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1 );
			dc.MoveTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset );
			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 5*offset/2-1, offset -1 );
			dc.LineTo( rcIcon.right - 3*offset/2, offset -1);		
		}
		// Restore the pen
		dc.SelectObject( pOldPen );	
	}	
	// Restore dc	
	dc.RestoreDC( nSavedDC );
	// Detach the dc before returning	
	dc.Detach();
}
int CXTPExcelTabCtrlTheme::DrawTab(CDC* pDC, CXTPExcelTabCtrl* pTabCtrl, const CPoint& pt, bool bSelected, CXTPTcbItem* pTcbItem)
{
	if (pDC == NULL || pTcbItem == NULL || !::IsWindow(pTabCtrl->GetSafeHwnd()))
		return -1;

	// Saves the current state of the device context, we will
	// restore the state when the method looses scope. This will
	// simplify selecting objects.
	const int nSavedDC = pDC->SaveDC();

	const int iHeight = m_cy;
	const int iBase = iHeight / 2;
	const int iWidth = iHeight + iHeight / 2; // 2 bases + 2 margins

	const bool bBottom = (pTabCtrl->GetTabStyle() & FTS_XTP_BOTTOM) == FTS_XTP_BOTTOM;

	pDC->SelectObject(pTabCtrl->GetTabFont(bSelected));
	const CSize szText = pDC->GetTextExtent(pTcbItem->szTabLabel);

	CRect rcText;
	rcText.left = pt.x + iBase + iBase / 2;
	rcText.top = pt.y + ((iHeight - szText.cy)/2)-1;
	rcText.right = rcText.left + szText.cx;
	rcText.bottom = rcText.top + szText.cy;

	COLORREF crBack = GetTabBackColor(pTcbItem);
	COLORREF crFore = GetTabTextColor(pTcbItem);

	if (bSelected)
	{
		crBack = GetSelTabBackColor(pTcbItem);
		crFore = GetSelTabTextColor(pTcbItem);
	}

	CPen penBack(PS_SOLID, 1, crBack);
	CPen penWindow(PS_SOLID, 1, m_clr3DHilight);
	CPen penShadow(PS_SOLID, 1, m_clr3DShadow);
	CPen penOutline(PS_SOLID, 1, m_clrBtnText);

	CBrush brush;
	brush.CreateSolidBrush(crBack);

	POINT points[] =
	{
		{ pt.x, pt.y + iHeight - 1 },
		{ pt.x + iBase - 1, pt.y               },
		{ pt.x + szText.cx + iWidth - iBase - 1, pt.y               },
		{ pt.x + szText.cx + iWidth - 1, pt.y + iHeight - 1 }
	};

	// swap vertical coordinates
	if (bBottom)
	{
		points[0].y = points[1].y;
		points[2].y = points[3].y;
		points[1].y = points[2].y;
		points[3].y = points[0].y;
	}

	pDC->SelectObject(&penOutline);
	pDC->SetBkColor(crBack);
	pDC->SelectObject(&brush);
	pDC->Polygon(points, 4);
	pDC->SetTextColor(crFore);
	pDC->DrawText(pTcbItem->szTabLabel, rcText, DT_CENTER);
	pDC->SelectObject(&penShadow);

	if (bSelected)
	{
		pDC->MoveTo(pt.x + iBase, points[1].y);
		pDC->LineTo(pt.x + iBase * 2 + szText.cx - 1, points[1].y);
		pDC->SelectObject(&penBack);
		pDC->MoveTo(pt.x + 1, points[0].y);
		pDC->LineTo(pt.x + szText.cx + iWidth - 1, points[0].y);
	}
	else
	{
		// highlight line on left
		pDC->SelectObject(&penWindow);
		pDC->MoveTo(pt.x + 1, points[0].y);
		pDC->LineTo(pt.x + 1 + iBase, points[0].y + iHeight);

		// shadow line on top
		pDC->SelectObject(&penShadow);
		pDC->MoveTo(pt.x, points[0].y);
		pDC->LineTo(pt.x + szText.cx + iWidth, points[0].y);

		// shadow line on bottom
		pDC->MoveTo(pt.x + iBase, points[1].y);
		pDC->LineTo(pt.x + szText.cx + iHeight - 1, points[1].y);
	}

	// Cleanup.
	pDC->RestoreDC(nSavedDC);
	brush.DeleteObject();

	return szText.cx + iWidth;
}
void CFlatHeaderCtrl::DrawCtrl(CDC* pDC)
{
	CRect rectClip;
	if (pDC->GetClipBox(&rectClip) == ERROR)
		return;

	CRect rectClient, rectItem;
	GetClientRect(&rectClient);

    pDC->FillSolidRect(rectClip, m_cr3DFace);

	INT iItems = GetItemCount();
	ASSERT(iItems >= 0);

	CPen penHighLight(PS_SOLID, 1, m_cr3DHighLight);
	CPen penShadow(PS_SOLID, 1, m_cr3DShadow);
	CPen* pPen = pDC->GetCurrentPen();

	CFont* pFont = pDC->SelectObject(GetFont());

	pDC->SetBkColor(m_cr3DFace);
	pDC->SetTextColor(m_crText);

	INT iWidth = 0;

	for(INT i=0;i<iItems;i++)
	{
		INT iItem = OrderToIndex(i);

		TCHAR szText[FLATHEADER_TEXT_MAX];

		HDITEM hditem;
		hditem.mask = HDI_WIDTH|HDI_FORMAT|HDI_TEXT|HDI_IMAGE|HDI_BITMAP;
		hditem.pszText = szText;
		hditem.cchTextMax = sizeof(szText);
		VERIFY(GetItem(iItem, &hditem));

		VERIFY(GetItemRect(iItem, rectItem));

		if (rectItem.right >= rectClip.left || rectItem.left <= rectClip.right)
		{
			if(hditem.fmt&HDF_OWNERDRAW)
			{
				DRAWITEMSTRUCT disItem;
				disItem.CtlType = ODT_BUTTON;
				disItem.CtlID = GetDlgCtrlID();
				disItem.itemID = iItem;
				disItem.itemAction = ODA_DRAWENTIRE;
				disItem.itemState = 0;
				disItem.hwndItem = m_hWnd;
				disItem.hDC = pDC->m_hDC;
				disItem.rcItem = rectItem;
				disItem.itemData = 0;

				DrawItem(&disItem);
			}
			else
			{
				rectItem.DeflateRect(m_iSpacing, 0);
				DrawItem(pDC, rectItem, &hditem, iItem == m_iSortColumn, m_bSortAscending);
				rectItem.InflateRect(m_iSpacing, 0);

				if(m_nClickFlags&MK_LBUTTON && m_iHotIndex == iItem && m_hdhtiHotItem.flags&HHT_ONHEADER)
					pDC->InvertRect(rectItem);
			}

			if(i < iItems-1)
			{
				pDC->SelectObject(&penShadow);
				pDC->MoveTo(rectItem.right-1, rectItem.top+2);
				pDC->LineTo(rectItem.right-1, rectItem.bottom-2);

				pDC->SelectObject(&penHighLight);
				pDC->MoveTo(rectItem.right, rectItem.top+2);
				pDC->LineTo(rectItem.right, rectItem.bottom-2);
			}
		}

		iWidth += hditem.cxy;
	}

	if(iWidth > 0)
	{
		rectClient.right = rectClient.left + iWidth;
		pDC->Draw3dRect(rectClient, m_cr3DHighLight, m_cr3DShadow);
	}

	pDC->SelectObject(pFont);
	pDC->SelectObject(pPen);

	penHighLight.DeleteObject();
	penShadow.DeleteObject();
}
void CHeaderCtrlEx::DrawItem( LPDRAWITEMSTRUCT lpDrawItemStruct )
{
	CDC dc;

	dc.Attach( lpDrawItemStruct->hDC );

	// Get the column rect
	CRect rcLabel( lpDrawItemStruct->rcItem );

	// Save DC
	int nSavedDC = dc.SaveDC();

	// Set clipping region to limit drawing within column
	CRgn rgn;
	rgn.CreateRectRgnIndirect( &rcLabel );
	dc.SelectObject( &rgn );
	rgn.DeleteObject();

		// Draw the background
		dc.FillRect(rcLabel, &CBrush(::GetSysColor(COLOR_3DFACE)));
	
	// Labels are offset by a certain amount  
	// This offset is related to the width of a space character
	int offset = dc.GetTextExtent(L" ", 1 ).cx*2;


	// Get the column text and format
	wchar_t buf[256];
	HD_ITEM hditem;
	
	hditem.mask = HDI_TEXT | HDI_FORMAT;
	hditem.pszText = buf;
	hditem.cchTextMax = 255;

	GetItem( lpDrawItemStruct->itemID, &hditem );

	// Determine format for drawing column label
	UINT uFormat = DT_SINGLELINE | DT_NOPREFIX | DT_NOCLIP 
						| DT_VCENTER | DT_END_ELLIPSIS ;

	if( hditem.fmt & HDF_CENTER)
		uFormat |= DT_CENTER;
	else if( hditem.fmt & HDF_RIGHT)
		uFormat |= DT_RIGHT;
	else
		uFormat |= DT_LEFT;

	// Adjust the rect if the mouse button is pressed on it
	if( lpDrawItemStruct->itemState == ODS_SELECTED )
	{
		rcLabel.left++;
		rcLabel.top += 2;
		rcLabel.right++;
	}

	// Adjust the rect further if Sort arrow is to be displayed
	if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
	{
		rcLabel.right -= 3 * offset;
	}

	rcLabel.left += offset;
	rcLabel.right -= offset;

	// Draw column label
    if( rcLabel.left <rcLabel.right ) dc.DrawText(buf,-1,rcLabel, uFormat); // Draw the Sort arrow if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
	{
		CRect rcIcon( lpDrawItemStruct->rcItem );

		// Set up pens to use for drawing the triangle
		CPen penLight(PS_SOLID, 1, GetSysColor(COLOR_3DHILIGHT));
		CPen penShadow(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
		CPen *pOldPen = dc.SelectObject( &penLight );

		if( m_bSortAsc )
		{
			// Draw triangle pointing upwards
			dc.MoveTo( rcIcon.right - 2*offset, offset-1);
			dc.LineTo( rcIcon.right - 3*offset/2, rcIcon.bottom - offset );
			dc.LineTo( rcIcon.right - 5*offset/2-2, rcIcon.bottom - offset );
			dc.MoveTo( rcIcon.right - 5*offset/2-1, rcIcon.bottom - offset-1 );

			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 2*offset, offset-2);
		}
		else
		{
			// Draw triangle pointing downwords
			dc.MoveTo( rcIcon.right - 3*offset/2, offset-1);
			dc.LineTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset + 1 );
			dc.MoveTo( rcIcon.right - 2*offset-1, rcIcon.bottom - offset );

			dc.SelectObject( &penShadow );
			dc.LineTo( rcIcon.right - 5*offset/2-1, offset -1 );
			dc.LineTo( rcIcon.right - 3*offset/2, offset -1);
		}

		// Restore the pen
		dc.SelectObject( pOldPen );
	}

	// Restore dc
	dc.RestoreDC( nSavedDC );

	// Detach the dc before returning
	dc.Detach();
}