📄 readme.wzd
字号:
/////////////////////////////////////////////////////////////////////
// Modify the View Class.
/////////////////////////////////////////////////////////////////////
// 1) create a dialog class that will retrieve a report type (please see
// example on CD for an example
// 2) add the following to your view class:
int CWzdView::m_reportTabs[] = {1200,2000};
#define NUM_TABS sizeof(m_reportTabs)/sizeof(int)
/////////////////////////////////////////////////////////////////////////////
// CWzdView printing
#define LINES_IN_REPORT_TITLE 7
void CWzdView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo)
{
// get printed character height and width
TEXTMETRIC tm;
pDC->GetTextMetrics(&tm);
m_nPrintCharHeight=tm.tmHeight;
m_nPrintCharWidth=tm.tmAveCharWidth;
// get number of characters per line
int nPageWidth = pDC->GetDeviceCaps(HORZRES);
m_nPageWidth = nPageWidth/m_nPrintCharWidth;
// get number of lines per page (with and w/o title on each page)
int nPageHeight = pDC->GetDeviceCaps(VERTRES);
int nPrintLinesPerPage = nPageHeight / m_nPrintCharHeight;
m_nPrintableLinesPerPage=nPrintLinesPerPage-LINES_IN_REPORT_TITLE;
// determine number of total pages in this document
int nLines=GetDocument()->GetWzdInfoList()->GetCount();
int nPages=(nLines + m_nPrintableLinesPerPage - 1)/ m_nPrintableLinesPerPage;
if (nPages<=0) nPages=1;
pInfo->SetMaxPage(nPages);
pInfo->m_nCurPage = 1;
}
void CWzdView::OnFilePrint()
{
if (GetReportOptions())
{
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_FILE_PRINT);
}
}
void CWzdView::OnFilePrintPreview()
{
if (GetReportOptions())
{
AfxGetMainWnd()->SendMessage(WM_COMMAND, ID_FILE_PRINT_PREVIEW);
}
}
BOOL CWzdView::GetReportOptions()
{
CWzdDialog dlg;
dlg.m_nReportType=m_nReportType;
if(dlg.DoModal()==IDOK)
{
m_nReportType = dlg.m_nReportType;
return TRUE;
}
return FALSE;
}
void CWzdView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
{
// print title
int y=0;
PrintTitle(pDC,&y,pInfo);
// print column headers
PrintColumnHeaders(pDC,&y);
// determine part of document to print on this page
int nWzdInfoListInx=(pInfo->m_nCurPage-1)*m_nPrintableLinesPerPage;
int nWzdInfoListEnd=GetDocument()->GetWzdInfoList()->GetCount();
if (nWzdInfoListEnd>nWzdInfoListInx+m_nPrintableLinesPerPage)
{
nWzdInfoListEnd=nWzdInfoListInx+m_nPrintableLinesPerPage;
}
// print report lines
for (; nWzdInfoListInx<nWzdInfoListEnd; nWzdInfoListInx++)
{
POSITION pos=GetDocument()->GetWzdInfoList()->FindIndex(nWzdInfoListInx);
CWzdInfo *pInfo = GetDocument()->GetWzdInfoList()->GetAt(pos);
PrintLine(pDC,&y,pInfo);
y+=m_nPrintCharHeight;
}
CView::OnPrint(pDC, pInfo);
}
void CWzdView::PrintTitle(CDC *pDC, int *y, CPrintInfo* pInfo)
{
// title
int x=pDC->GetDeviceCaps(HORZRES);
pDC->SetTextAlign(TA_CENTER);
pDC->TextOut( x/2, *y, "WZD REPORT");
// page #
CString str;
str.Format("Page %d of %d",pInfo->m_nCurPage,pInfo->GetMaxPage());
pDC->SetTextAlign(TA_RIGHT);
pDC->TextOut( x, *y, str);
// report type
*y+=m_nPrintCharHeight;
pDC->SetTextAlign(TA_CENTER);
switch (m_nReportType)
{
case CWzdView::SHORTREPORT:
str="Short Report";
break;
case CWzdView::LONGREPORT:
str="Long Report";
break;
}
pDC->TextOut( x/2, *y, str);
// date
*y+=m_nPrintCharHeight;
COleDateTime dt(COleDateTime::GetCurrentTime());
pDC->TextOut( x/2, *y, dt.Format("%c"));
*y+=m_nPrintCharHeight;
*y+=m_nPrintCharHeight; //leave space between title and column headers
}
void CWzdView::PrintColumnHeaders(CDC *pDC, int *y)
{
CString str;
switch (m_nReportType)
{
case CWzdView::SHORTREPORT:
str="Group\tVersion";
break;
case CWzdView::LONGREPORT:
str="Group\tComment\tVersion";
break;
}
pDC->SetTextAlign(TA_LEFT);
pDC->TabbedTextOut(0,*y,str,NUM_TABS,m_reportTabs,0);
*y+=m_nPrintCharHeight;
*y+=m_nPrintCharHeight; //leave space between column headers and report
}
void CWzdView::PrintLine(CDC *pDC, int *y, CWzdInfo *pInfo)
{
CString str;
switch (m_nReportType)
{
case CWzdView::SHORTREPORT:
str.Format("%s\t%d",pInfo->m_sGroupName, pInfo->m_nVersion);
break;
case CWzdView::LONGREPORT:
str.Format("%s\t%s\t%d",pInfo->m_sGroupName, pInfo->m_sComment, pInfo->m_nVersion );
break;
}
pDC->SetTextAlign(TA_LEFT);
pDC->TabbedTextOut(0,*y,str,NUM_TABS,m_reportTabs,0);
*y+=m_nPrintCharHeight;
}
/////////////////////////////////////////////////////////////////////
// From: Visual C++ MFC Programming by Example by John E. Swanke
// Copyright (C) 1999 jeswanke. All rights reserved.
/////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -