FileListHead.cpp
资源名称:DXGuide.zip [点击查看]
上传用户:wymy58
上传日期:2007-01-07
资源大小:2086k
文件大小:4k
源码类别:
DirextX编程
开发平台:
Visual C++
- // FileListHead.cpp : implementation file
- //
- #include "stdafx.h"
- #include "PFM.h"
- #include "FileListHead.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CFileListHead
- CFileListHead::CFileListHead()
- {
- m_nSortCol = -1;
- }
- CFileListHead::~CFileListHead()
- {
- }
- BEGIN_MESSAGE_MAP(CFileListHead, CHeaderCtrl)
- //{{AFX_MSG_MAP(CFileListHead)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CFileListHead message handlers
- int CFileListHead::SetSortImage( int nCol, BOOL bAsc )
- {
- int nPrevCol = m_nSortCol;
- m_nSortCol = nCol;
- m_bSortAsc = bAsc;
- // Change the item to ownder drawn
- HD_ITEM hditem;
- hditem.mask = HDI_FORMAT;
- GetItem( nCol, &hditem );
- hditem.fmt |= HDF_OWNERDRAW;
- SetItem( nCol, &hditem );
- // Invalidate header control so that it gets redrawn
- Invalidate();
- return nPrevCol;
- }
- void CFileListHead::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_BTNFACE)));
- // 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++;
- }
- CRect rcIcon(rcLabel);
- rcIcon.top +=2;
- rcIcon.left +=2;
- // Adjust the rect further if Sort arrow is to be displayed
- if( lpDrawItemStruct->itemID == (UINT)m_nSortCol )
- {
- rcLabel.left += offset;
- }
- rcLabel.left += 2*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 penLine(PS_SOLID, 1, GetSysColor(COLOR_BTNTEXT));
- CPen *pOldPen = dc.SelectObject( &penLine );
- if( m_bSortAsc )
- {
- // Draw triangle pointing upwards
- dc.MoveTo( rcIcon.left, rcIcon.top + 2*offset );
- dc.LineTo( rcIcon.left+offset, rcIcon.top);
- dc.LineTo( rcIcon.left+2*offset+1,rcIcon.top + 2*offset);
- dc.MoveTo( rcIcon.left+offset, rcIcon.top);
- dc.LineTo( rcIcon.left+offset, rcIcon.bottom);
- }
- else
- {
- // Draw triangle pointing downwords
- dc.MoveTo( rcIcon.left, rcIcon.bottom - 2*offset );
- dc.LineTo( rcIcon.left+offset, rcIcon.bottom);
- dc.LineTo( rcIcon.left+2*offset+1,rcIcon.bottom - 2*offset);
- dc.MoveTo( rcIcon.left+offset, rcIcon.bottom);
- dc.LineTo( rcIcon.left+offset, rcIcon.top);
- }
- // Restore the pen
- dc.SelectObject( pOldPen );
- }
- // Restore dc
- dc.RestoreDC( nSavedDC );
- // Detach the dc before returning
- dc.Detach();
- }