?? myprint.cpp
字號:
// MyPrint.cpp: implementation of the MyPrint class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "MyPrint.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
MyPrint::MyPrint()
{
m_minpage = 1;
m_maxpage = 1;
m_curpage = 1;
pos_x = 200;
pos_y = 400;
cur_x = 200;
cur_y = 400;
}
MyPrint::~MyPrint()
{
m_font.Detach();
printdc.Detach();
::DeleteDC(printdc);
}
void MyPrint::SetFont(int height,int weight,bool bItalic,bool bUnderline,CString font)
{
m_font.CreateFont(height,0,0,0,weight,bItalic,bUnderline,0,DEFAULT_CHARSET,0,0,0,0,font);
}
bool MyPrint::InitPrint(int itemy)
{
m_itemy = itemy;
CPrintDialog printDlg(FALSE);
//利用CPrintDialog 生成打印機設備環境
if (printDlg.DoModal() == IDCANCEL) return false;
// 連接到dc上
printdc.Attach(printDlg.CreatePrinterDC());
printdc.m_bPrinting = TRUE;
printdc.SetMapMode(MM_LOMETRIC);
// 設置字體
oldfont = printdc.SelectObject(&m_font);
// 計算字體
nHorRes = printdc.GetDeviceCaps(HORZRES);
nVerRes = printdc.GetDeviceCaps(VERTRES);
TEXTMETRIC tm;
printdc.GetTextMetrics(&tm);
nCharHeight = tm.tmHeight;
nCharWidth = tm.tmAveCharWidth;
pageend_y = nVerRes - 150;
// 設置打印作業
CString strTitle;
strTitle.LoadString(AFX_IDS_APP_TITLE);
// 打印作業的定義信息
::ZeroMemory (&di, sizeof (DOCINFO));
di.cbSize = sizeof (DOCINFO);
di.lpszDocName = strTitle;
return true;
}
BOOL MyPrint::StratPrint(void)
{
BOOL bPrintingOK = printdc.StartDoc(&di);
bPrintingOK &= printdc.StartPage();
return bPrintingOK;
}
void MyPrint::EndPrint(void)
{
CString str;
str.Format("-- 完 --",m_curpage);
int startx = 40 * str.GetLength();
printdc.SelectObject(oldfont);
printdc.TextOut(nHorRes - startx,nVerRes - 70 ,str);
printdc.EndPage();
printdc.EndDoc();
}
void MyPrint::PrintStr(CString str)
{
printdc.SelectObject(&m_font);
printdc.TextOut(cur_x,cur_y,str);
cur_y += nCharHeight + m_itemy;
if(cur_y >= pageend_y)
{
Nextpage();
}
}
void MyPrint::PrintHead(CString str)
{
printdc.SelectObject(&m_font);
printdc.TextOut(100,50,str);
}
void MyPrint::Nextpage(void)
{
CString str;
str.Format("-- 第 %d 頁 --",m_curpage);
int startx = 40 * str.GetLength();
printdc.SelectObject(oldfont);
printdc.TextOut(nHorRes - startx,nVerRes - 70 ,str);
printdc.EndPage();
printdc.StartPage();
cur_x = pos_x;
cur_y = pos_y;
m_curpage++;
}
void MyPrint::SetPosX(int x)
{
pos_x = x;
}
void MyPrint::SetPosY(int y)
{
pos_y = y;
}
void MyPrint::SetCurX(int x)
{
cur_x = x;
}
void MyPrint::SetCurY(int y)
{
cur_y = y;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -