preview.cpp
来自「Visual C++ 的学习资料一」· C++ 代码 · 共 139 行
CPP
139 行
// Preview.cpp : implementation file
//
#include "stdafx.h"
#include "printerpreview.h"
#include "Preview.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPreview dialog
CPreview::CPreview(CWnd* pParent /*=NULL*/)
: CDialog(CPreview::IDD, pParent)
{
//{{AFX_DATA_INIT(CPreview)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CPreview::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPreview)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPreview, CDialog)
//{{AFX_MSG_MAP(CPreview)
ON_WM_PAINT()
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPreview message handlers
BOOL CPreview::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
sarrays[0][0]="部门编号";
sarrays[0][1]="部门名称";
sarrays[0][2]="负责人";
ADOConn m_AdoConn;
m_AdoConn.OnInitADOConn();
CString sql;
sql.Format("select* from department order by 部门编号");
m_AdoConn.GetRecordSet((_bstr_t)sql);
int i=1;
while(m_AdoConn.m_pRecordset->adoEOF==0)
{
sarrays[i][0] = (char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("部门编号");
sarrays[i][1] = (char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("部门名称");
sarrays[i][2] = (char*)(_bstr_t)m_AdoConn.m_pRecordset->GetCollect("负责人");
i++;
m_AdoConn.m_pRecordset->MoveNext();
}
m_AdoConn.ExitConnect();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPreview::OnPaint()
{
CPaintDC dc(this); // device context for painting
// TODO: Add your message handler code here
CRect m_rect;
GetClientRect(m_rect);
CDC* pDC = GetDC();
DrawReport(m_rect,GetDC(),false);
// Do not call CDialog::OnPaint() for painting messages
}
HBRUSH CPreview::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
CBrush m_brush (RGB(255,255,255));
CRect m_rect;
GetClientRect(m_rect);
pDC->FillRect(m_rect,&m_brush);
// TODO: Return a different brush if the default is not desired
return m_brush;
}
void CPreview::DrawReport(CRect rect, CDC *pDC, BOOL isprinted)
{
titlefont.CreatePointFont(200,"宋体",pDC);
bodyfont.CreatePointFont(120,"宋体",pDC);
if (!isprinted) //预览
{
rect.DeflateRect(0,20,0,0);
pDC->DrawText("人员表",rect,DT_CENTER);
pDC->SelectObject(&bodyfont);
CRect m_rect(rect);
CRect temprect(m_rect.left+100,m_rect.top+40,100+(m_rect.Width())/4,
m_rect.bottom+100);
CRect itemrect;
int width = temprect.Width();
for (int i = 0;i<3;i++)
{
itemrect.CopyRect(temprect);
for (int y = 0; y< 7;y++)
{
itemrect.DeflateRect(0,20);
pDC->DrawText(sarrays[y][i],itemrect,DT_LEFT);
}
temprect.DeflateRect(width,0,0,0);
temprect.InflateRect(0,0,width,0);
}
}
titlefont.DeleteObject();
bodyfont.DeleteObject();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?