📄 thclistview.cpp
字号:
////////////////////////////////////////////////////////////////
// Copyright 2002-5-13~15 Tang.H.C
// If this code works, it was written by Tang.H.C.
// If not, I don't know who wrote it.
#include "stdafx.h"
#include "ThcListView.h"
#include "SqlCommandDoc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CConfig config;
/////////////////////////////////////////////////////////////////////////////
// CThcListView
CThcListView::CThcListView()
{
/* m_nSortedCol = -1;
m_bSortAscending = TRUE;
m_bSaveColumnState = FALSE;
m_strSection.Empty();
m_strControl.Empty();*/
TRACE0("thc:CThcListView::CThcListView()\n");
m_sTitle="统计列表";
for(int i=0;i<THCMAXCOLNUM;i++)
{
m_DataTypeFlag[i]=0;
m_iColumnWidth[i]=60;
}
}
CThcListView::~CThcListView()
{
}
IMPLEMENT_DYNCREATE(CThcListView, CListView)
BEGIN_MESSAGE_MAP(CThcListView, CListView)
//{{AFX_MSG_MAP(CThcListView)
ON_NOTIFY(HDN_ITEMCLICKA, 0, OnItemclick)
ON_WM_DESTROY()
ON_NOTIFY(HDN_ITEMCLICKW, 0, OnItemclick)
//}}AFX_MSG_MAP
ON_COMMAND(ID_FILE_PRINT, CListView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CListView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CThcListView message handlers
void CThcListView::SetColSortDataType(int iColIndex, int iDataType)
{
m_DataTypeFlag[iColIndex]=iDataType;
}
void CThcListView::SetColSort(int iColIndex,bool bAscSort )
{
int iLastCol=m_HeaderCtrl.GetLastColumn();
m_HeaderCtrl.RemoveSortImage(iLastCol);
if( bAscSort )
{
m_HeaderCtrl.m_lColumnSortStates=0;
m_HeaderCtrl.m_lColumnSortStates^=(1<<iColIndex);
}
else
m_HeaderCtrl.m_lColumnSortStates=0;
CSortClass::EDataType dataType;
CSortClass csc(&GetListCtrl(), iColIndex);
switch( m_DataTypeFlag[iColIndex] )
{
case 0:
dataType=CSortClass::dtINT;
//csc.Sort(m_bSortAscending, dataType);
break;
case 1:
//SortTextItems( m_nSortedCol, m_bSortAscending );
dataType=CSortClass::dtSTRING;
//csc.Sort(m_bSortAscending, dataType);
break;
case 2:
dataType=CSortClass::dtDATETIME;
//csc.Sort(m_bSortAscending, dataType);
break;
case 3:
dataType=CSortClass::dtDEC;
//csc.Sort(m_bSortAscending, dataType);
break;
default:
ASSERT("Error: attempt to sort a column without type.");
}
csc.Sort(bAscSort, dataType);
m_HeaderCtrl.SetSortImageStandard(iColIndex, bAscSort);
}
void CThcListView::SetPrintHeadline(CString str)
{
m_sTitle=str;
}
void CThcListView::OnItemclick(NMHDR* pNMHDR, LRESULT* pResult)
{
HD_NOTIFY *phdn = (HD_NOTIFY *) pNMHDR;
if( phdn->iButton == 0 )
{
// User clicked on header using left mouse button
bool m_bSortAscending=m_HeaderCtrl.GetItemSortState( phdn->iItem );
///////////////////////////////////////////Tang.H.C 2002-5-13
int iLastCol=m_HeaderCtrl.GetLastColumn();
m_HeaderCtrl.RemoveSortImage(iLastCol);
CSortClass::EDataType dataType;
CSortClass csc(&GetListCtrl(), phdn->iItem);
switch( m_DataTypeFlag[phdn->iItem] )
{
case 0:
dataType=CSortClass::dtINT;
//csc.Sort(m_bSortAscending, dataType);
break;
case 1:
//SortTextItems( m_nSortedCol, m_bSortAscending );
dataType=CSortClass::dtSTRING;
//csc.Sort(m_bSortAscending, dataType);
break;
case 2:
dataType=CSortClass::dtDATETIME;
//csc.Sort(m_bSortAscending, dataType);
break;
case 3:
dataType=CSortClass::dtDEC;
//csc.Sort(m_bSortAscending, dataType);
break;
default:
ASSERT("Error: attempt to sort a column without type.");
}
csc.Sort(m_bSortAscending, dataType);
m_HeaderCtrl.SetSortImageStandard(phdn->iItem, m_bSortAscending);
}
*pResult = 0;
}
void CThcListView::BuildColumns(int nCols, int * nWidth, CString * strCol)
{
//insert columns
//CListCtrl& ListCtrl=GetListCtrl();
int i;
LV_COLUMN lvc;
m_iColNum=nCols;
lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT ;//| LVCF_SUBITEM;
CString strTemp;
for(i = 0; i < nCols; i++)
{
//lvc.iSubItem = i;
strTemp=strCol[i];
lvc.pszText = (char*)(LPCTSTR)strTemp;
lvc.cx = nWidth[i];
m_iColumnWidth[i]=nWidth[i]/15;
lvc.fmt = LVCFMT_CENTER;
GetListCtrl().InsertColumn(i,&lvc);
}
}
/*/ ie: LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP
void CThcListView::SetExtendedStyle(DWORD dwNewStyle)
{
// Returns the current extended style ( a DWORD ).
DWORD dwStyle = ::SendMessage (GetListCtrl().m_hWnd, LVM_GETEXTENDEDLISTVIEWSTYLE, 0, 0);
// Add the full row select and grid line style to the existing extended styles.
dwStyle |= dwNewStyle;
// Sets the current extended style ( a DWORD ).
::SendMessage (GetListCtrl().m_hWnd, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, dwStyle);
}*/
/*///////////////////////////////////////////////////////
BOOL CThcListView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Add your specialized code here and/or call the base class
cs.style &= ~LVS_TYPEMASK;
cs.style |= LVS_SHOWSELALWAYS | LVS_REPORT ;
return CThcListView::PreCreateWindow(cs);
}*/
void CThcListView::OnDestroy()
{
//if (m_bSaveColumnState)
//SaveColumnWidths();
CListView::OnDestroy();
}
void CThcListView::OnInitialUpdate()
{
//call CView::OnInitialUpdate(){OnUpdate(NULL,0,NULL);}
//CListView::OnInitialUpdate();
if (!m_HeaderCtrl.SubclassWindow(GetDlgItem(0)->GetSafeHwnd()))
AfxMessageBox("Error!");
CListCtrl& ListCtrl=GetListCtrl();
DWORD j=ListCtrl.GetExtendedStyle()| LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP |LVS_EX_TWOCLICKACTIVATE|LVS_EX_FULLROWSELECT;
ListCtrl.SetExtendedStyle(j);
SetListViewPrintFont();
//m_headerCtrl.FlatHeader();
//SaveColumnState(_T("Settings"), _T("Control"));
//InitializeFlatHeader();
}
/*int CThcListView::InitializeFlatHeader()
{
/* if (!m_HeaderCtrl.SubclassWindow(GetDlgItem(0)->GetSafeHwnd()))
return -1;
//m_headerCtrl.FlatHeader();
//SaveColumnState(_T("Settings"), _T("Control"));
CListCtrl& ListCtrl=GetListCtrl();
DWORD j=ListCtrl.GetExtendedStyle()| LVS_EX_GRIDLINES | LVS_EX_HEADERDRAGDROP |LVS_EX_TWOCLICKACTIVATE|LVS_EX_FULLROWSELECT;
ListCtrl.SetExtendedStyle(j);
SetListViewPrintFont();
return 0;
}*/
BOOL CThcListView::OnPreparePrinting(CPrintInfo* pInfo)
{
// TODO: call DoPreparePrinting to invoke the Print dialog box
return CListView::DoPreparePrinting(pInfo);
}
void CThcListView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
//int m_iColumnWidth[50];
int Vpage;
m_iHpage=MaxHPage(pDC,m_logfont,m_iColNum,m_iColumnWidth,m_iXnumber);
Vpage=MaxVPage(pDC,m_logfont,m_iVnumber);
pInfo->SetMaxPage(Vpage*m_iHpage);
CListView::OnBeginPrinting(pDC, pInfo);
}
void CThcListView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
m_iCurPage=pInfo->m_nCurPage;
OnDraw(pDC);
CListView::OnPrint(pDC, pInfo);
}
void CThcListView::OnDraw(CDC* pDC)
{
// TODO: Add your specialized code here and/or call the base class
int AlignText[30];
AlignText[0]=-1;
PrintText(pDC,GetListCtrl(),m_logfont,m_iColNum,m_iColumnWidth,m_iCurPage,m_iHpage,m_iXnumber,
m_iVnumber,AlignText,m_sTitle);
}
void CThcListView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// TODO: Add your specialized code here and/or call the base class
CListView::OnEndPrinting(pDC, pInfo);
}
void CThcListView::PrintText(CDC *pDC,CListCtrl &ctlList,LOGFONT logfont,int nColumn,int *ColumnWidth,int Curpage,int Hpage,int *xnumber,int vnumber,int *AlignText,CString strtext)
{
pDC->SetBkMode(TRANSPARENT);
CBrush brush;
CPen BlackSolidPen,BlackDashPen;
CPen *pOldPen;
BlackSolidPen.CreatePen(PS_SOLID,5,RGB(0,0,0));
BlackDashPen.CreatePen(PS_DOT,1,RGB(0,0,0));
brush.CreateSolidBrush(RGB(192,192,192));
CFont newfont;
CFont *pOldFont;
int cyPage,cxPage;
int ptrate;
cxPage=pDC->GetDeviceCaps(HORZRES);
cyPage=pDC->GetDeviceCaps(VERTRES);
ptrate = cxPage*8/10/800+1;
//logfont.lfHeight=24;
logfont.lfHeight*=ptrate;
newfont.CreateFontIndirect(&logfont);
pOldFont=pDC->SelectObject(&newfont);
static TCHAR szBuff[MAX_PATH];
LVCOLUMN Column;
Column.mask=LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
Column.cchTextMax=sizeof(szBuff);
Column.pszText=szBuff;
int len=abs(logfont.lfHeight);//thc--logfont.lfHeight smaller than zero.
int StartX=50*ptrate;
int EndX=StartX;
int StartY=50*ptrate;
int EndY=StartY+len;
CRect rect,rect1;
rect.top=StartY;
rect.bottom=rect.top+len+5;//thc--MaxVpage same
rect1.top=StartY;
rect1.bottom=rect.top+len+5;
int length;
CString str;
//thc--len<-->abs(logfont.lfHeight) should be abs(logfont.lfWidth)*ptrate
pDC->TextOut((cxPage-strtext.GetLength()*len)/2,30,strtext);//*len
//////////////////////////////////////
str.Format("第%d页",Curpage);
pDC->TextOut(cxPage-300,30,str);
pOldPen=pDC->SelectObject(&BlackSolidPen);
pDC->MoveTo(20,30+len+10);
pDC->LineTo(cxPage-20,30+len+10);
//thc--pDC->SelectObject(pOldPen);
pOldPen=pDC->SelectObject(&BlackDashPen);
pDC->MoveTo(20,30+len+20);
pDC->LineTo(cxPage-20,30+len+20);
pDC->SelectObject(pOldPen);
int CurGrow=0;//index of first column of current page
int nGrow=0;//number of column of current page
int Hnum;//Hnum=Curpage%Hpage
int CurPage1;//namely,counttype-->Curpage%Hpage.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -