📄 wzdview.cpp
字号:
// WzdView.cpp : implementation of the CWzdView class
//
#include "stdafx.h"
#include "Wzd.h"
#include "WzdDoc.h"
#include "WzdView.h"
#include "WzdDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int CWzdView::m_reportTabs[] = {1200,2000};
#define NUM_TABS sizeof(m_reportTabs)/sizeof(int)
/////////////////////////////////////////////////////////////////////////////
// CWzdView
IMPLEMENT_DYNCREATE(CWzdView, CView)
BEGIN_MESSAGE_MAP(CWzdView, CView)
//{{AFX_MSG_MAP(CWzdView)
ON_COMMAND(IDC_FILE_PRINT, OnFilePrint)
ON_COMMAND(IDC_FILE_PRINT_PREVIEW, OnFilePrintPreview)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CWzdView construction/destruction
CWzdView::CWzdView()
{
m_nReportType=0;
}
CWzdView::~CWzdView()
{
}
BOOL CWzdView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CWzdView drawing
void CWzdView::OnDraw(CDC* pDC)
{
CWzdDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CWzdView printing
#define LINES_IN_REPORT_TITLE 7
BOOL CWzdView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
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::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CWzdView diagnostics
#ifdef _DEBUG
void CWzdView::AssertValid() const
{
CView::AssertValid();
}
void CWzdView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CWzdDoc* CWzdView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWzdDoc)));
return (CWzdDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CWzdView message handlers
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;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -