⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scoreprintdlg.cpp

📁 课程设计的简单Access学生数据库系统
💻 CPP
字号:
// ScorePrintDlg.cpp : implementation file
//

#include "stdafx.h"
#include "sm.h"
#include "score.h"
#include "scorelist.h"
#include "printremark.h"
#include "ScorePrintDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CScorePrintDlg dialog


//##ModelId=40A481F4032D
CScorePrintDlg::CScorePrintDlg(ScoreList *plist, CString *class_title, CString *teacher, CWnd* pParent /*=NULL*/)
	: CDialog(CScorePrintDlg::IDD, pParent),Remark(""), PreViewDlg(plist, &Remark)
{
	//{{AFX_DATA_INIT(CScorePrintDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	pList = plist;
	pTeacher = teacher;
	pClass = class_title;
}


//##ModelId=40A481F4035E
void CScorePrintDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScorePrintDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScorePrintDlg, CDialog)
	//{{AFX_MSG_MAP(CScorePrintDlg)
	ON_BN_CLICKED(IDC_BUTTON1, OnButtonRemark)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScorePrintDlg message handlers

//##ModelId=40A481F4036C
BOOL CScorePrintDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	CRect rc;
	GetClientRect(&rc);
	PreViewDlg.Create(IDD_DIALOG_PREVIEW, this);
	rc.left+=10, rc.top+=10, rc.bottom-=35, rc.right-=10;
	PreViewDlg.MoveWindow(rc,false);
	PreViewDlg.ShowWindow(SW_SHOW);
	CDaoTableDef td(&theDatabase);
	td.Open("Unit");
	CDaoRecordset rs;
	rs.Open(&td);
	rs.SetCurrentIndex("id");
	if(rs.Seek("=", &COleVariant(1L)))
	{
		StrUnit = V_BSTRT(&rs.GetFieldValue("unit"));
	}
	rs.Close();
	td.Close();
	PreViewDlg.Set(pClass, pTeacher, &StrUnit);
	PreView();
		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

//##ModelId=40A481F4032C
void CScorePrintDlg::PreView()
{
	
}

//##ModelId=40A481F4036E
void CScorePrintDlg::OnOK() 
{
	CPrintDialog dlg(false);
	
	if(IDOK==dlg.DoModal())
	{
		CDC dc;
		if(!dc.Attach(dlg.GetPrinterDC()))
		{
			AfxMessageBox("无法打印");
			return;
		}
		DOCINFO di;
		ZeroMemory(&di, sizeof(DOCINFO));
		di.cbSize = sizeof (DOCINFO);
		di.lpszDocName = "成绩单打印";//
		CPrintInfo Info;//
		Info.m_rectDraw.SetRect(80,60,
			dc.GetDeviceCaps(HORZRES)-30, 
			dc.GetDeviceCaps(VERTRES)-60);//设置范围
		
		dc.SetMapMode(MM_ANISOTROPIC); 
		CDC *pDC = GetDC();
		//得到设备坐标和逻辑坐标的比例
		int stx = pDC->GetDeviceCaps(HORZRES);
		int sty = pDC->GetDeviceCaps(VERTRES);
		int ptx = dc.GetDeviceCaps(HORZRES);
		int pty = dc.GetDeviceCaps(VERTRES);
		int sx = pDC->GetDeviceCaps(LOGPIXELSX); 
		int sy = pDC->GetDeviceCaps(LOGPIXELSY);
		int px = dc.GetDeviceCaps(LOGPIXELSX); 
		int py = dc.GetDeviceCaps(LOGPIXELSY);
		pDC->DeleteDC();

	
		long xExt = (long)(float)px/sx ;
		long yExt = (long)(float)py/sy;
		dc.SetWindowExt(sx, sy);
		dc.SetViewportExt((int)px, (int)py);
		dc.SetViewportOrg(30*xExt,80*yExt);

		if(dc.StartDoc(&di)==-1)
		{
			AfxMessageBox("无法打印");
			dc.AbortDoc();
			DeleteDC(dc.Detach());
		//	dc.DeleteDC();
			return;
		}
		dc.StartPage();
		PreViewDlg.Draw(dc);
		dc.EndPage();
		dc.EndDoc();
		DeleteDC(dc.Detach());
		
	};	
}

//##ModelId=40A481F4037B
void CScorePrintDlg::OnButtonRemark() 
{
	CPrintRemark dlg(&Remark);
	dlg.DoModal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -