📄 reportheaderctrl.cpp
字号:
// ReportHeaderCtrl.cpp : implementation file
//
#include "stdafx.h"
//#include "Kvip.h"
#include "ReportHeaderCtrl.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CReportHeaderCtrl
CReportHeaderCtrl::CReportHeaderCtrl()
{
m_iSortColumn = -1;
m_iSortAscending = 0;
}
CReportHeaderCtrl::~CReportHeaderCtrl()
{
}
BEGIN_MESSAGE_MAP(CReportHeaderCtrl, CHeaderCtrl)
//{{AFX_MSG_MAP(CReportHeaderCtrl)
ON_WM_PAINT()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CReportHeaderCtrl message handlers
int CReportHeaderCtrl::GetSortedColumn() const
{
return m_iSortColumn;
}
int CReportHeaderCtrl::IsSortAscending() const
{
return m_iSortAscending;
}
void CReportHeaderCtrl::SetSortAscending(int iAscending)
{
m_iSortAscending = iAscending;
}
void CReportHeaderCtrl::SetSortedColumn(int nCol)
{
m_iSortColumn = nCol;
}
void CReportHeaderCtrl::UpdateSortArrow()
{
// change the item to owner drawn.
HD_ITEM hditem;
hditem.mask = HDI_FORMAT;
VERIFY(GetItem(m_iSortColumn, &hditem));
//hditem.fmt |= HDF_OWNERDRAW;
VERIFY(SetItem(m_iSortColumn, &hditem));
// invalidate the header control so it gets redrawn
Invalidate();
}
///////////////////////////////////////////////////////////////////////////////
// DrawCtrl
void CReportHeaderCtrl::DrawCtrl(CDC *pDC)
{
// draw the sort arrow.
CRect rcIcon;
if(m_iSortColumn <= 0 || m_iSortAscending == 0)
return ;
VERIFY(GetItemRect(m_iSortColumn, rcIcon));
const int iOffset = (rcIcon.bottom - rcIcon.top) / 4;
// 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 = pDC->SelectObject(&penLight);
if(m_iSortAscending > 0)
{
// draw the arrow pointing upwards.
pDC->MoveTo(rcIcon.right - 2 * iOffset, iOffset);
pDC->LineTo(rcIcon.right - iOffset, rcIcon.bottom - iOffset - 1);
pDC->LineTo(rcIcon.right - 3 * iOffset - 2, rcIcon.bottom - iOffset - 1);
(void)pDC->SelectObject(&penShadow);
pDC->MoveTo(rcIcon.right - 3 * iOffset - 1, rcIcon.bottom - iOffset - 1);
pDC->LineTo(rcIcon.right - 2 * iOffset, iOffset - 1);
}
else if(m_iSortAscending < 0)
{
// draw the arrow pointing downwards.
pDC->MoveTo(rcIcon.right - iOffset - 1, iOffset);
pDC->LineTo(rcIcon.right - 2 * iOffset - 1, rcIcon.bottom - iOffset);
(void)pDC->SelectObject(&penShadow);
pDC->MoveTo(rcIcon.right - 2 * iOffset - 2, rcIcon.bottom - iOffset);
pDC->LineTo(rcIcon.right - 3 * iOffset - 1, iOffset);
pDC->LineTo(rcIcon.right - iOffset - 1, iOffset);
}
return ;
}
void CReportHeaderCtrl::OnPaint()
{
// TODO: Add your message handler code here
// CPaintDC dc(this); // device context for painting
CHeaderCtrl::OnPaint();
//强制绘制后加入,顺序或倒序标志
CDC *pDC = GetWindowDC();
DrawCtrl(pDC);
// Do not call CHeaderCtrl::OnPaint() for painting messages
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -