打印问题!急!!

xiyupiaopiao 2007-01-27 01:47:33
F222011_T F224041_T F224042_T F226021_T L226001_T P222012_T P222013_T
2006-9-18 20:23:30 23 23 23 23 23 23 23
2006-9-18 20:23:31 24 24 24 24 24 24 24
2006-9-18 20:23:32 25 25 25 25 25 25 25
2006-9-18 20:23:33 26 26 26 26 26 26 26
2006-9-18 20:23:34 27 27 27 27 27 27 27
2006-9-18 20:23:35 28 28 28 28 28 28 28
2006-9-18 20:23:36 29 29 29 29 29 29 29
2006-9-18 20:23:37 30 30 30 30 30 30 30
2006-9-18 20:23:38 31 31 31 31 31 31 31
2006-9-18 20:23:39 32 32 32 32 32 32 32
2006-9-18 20:23:40 33 33 33 33 33 33 33
2006-9-18 20:23:41 34 34 34 34 34 34 34
2006-9-18 20:23:42 35 35 35 35 35 35 35
怎么把这些数据填在格子里打印输出,不用报表
...全文
230 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiyupiaopiao 2007-01-28
  • 打赏
  • 举报
回复
up
xiyupiaopiao 2007-01-27
  • 打赏
  • 举报
回复
我总共有300行,8列,怎么根据打印机横向,纵向设置自动调整表格和字体大小,使得表格充满整页.
下面是我的一段代码,哪位大虾帮忙该一下,改好了另开100分相送.谢谢
CRect rect;
CPen penBlack;
CString str,str1,str2;
CPrintDialog m_print(FALSE);
//m_print.DoModal();
//m_print.GetDefaults();
int cols = m_GridData.GetColumnCount();
int rows = m_GridData.GetRowCount();
CDC PrintDC;
penBlack.CreatePen(PS_SOLID, 3, RGB(0, 0, 0));

DOCINFO docinfo;
if (m_print.DoModal() == IDCANCEL)
return;
HDC hdcPrinter = m_print.GetPrinterDC();
if (hdcPrinter == NULL)
{
MessageBox(_T("打印机忙!"));
}
else
{
// create a CDC and attach it to the default printer

PrintDC.Attach(hdcPrinter);
}
CPen* pOldPen = PrintDC.SelectObject(&penBlack);
PrintDC.m_bPrinting = TRUE;
//取打印机的横方向和纵方向的分辨率
//即每英寸点数
short cxInch = PrintDC.GetDeviceCaps(LOGPIXELSX);
short cyInch = PrintDC.GetDeviceCaps(LOGPIXELSY);

//此处取纸的尺寸,单位毫米
CSize size;
size.cx = PrintDC.GetDeviceCaps(HORZSIZE);
size.cy = PrintDC.GetDeviceCaps(VERTSIZE);

//根据字体宽度、高度计算
//每行最大字数及每页最大行数
//取打印纸张高度和宽度
int nPageHeight, nPageWidth;
nPageHeight = PrintDC.GetDeviceCaps(VERTRES);
nPageWidth = PrintDC.GetDeviceCaps(HORZRES);
TEXTMETRIC TextM;
PrintDC.GetTextMetrics(&TextM);
//字体高度
short m_LineHeight = (unsigned short)TextM.tmHeight;
//字体平均宽度
short m_CharWidth=(unsigned short)
TextM.tmAveCharWidth;
//每行最大字数
short m_MaxLineChar = nPageWidth / m_CharWidth - 8;
//每页最大行数
short m_LinesPerPage = nPageHeight/ m_LineHeight;
//总共页数
unsigned short MaxPage = (int)(rows)/m_LinesPerPage;



docinfo.fwType=0;
docinfo.lpszDatatype=NULL;
docinfo.lpszDocName="文本文件打印";
docinfo.cbSize=sizeof(DOCINFO);
docinfo.lpszOutput=NULL;
//AfxGetApp()->CreatePrinterDC(PrintDC);
//HDC hPrinter=PrintDC.GetSafeHdc();
PrintDC.StartDoc(&docinfo);
int posIndex=0;
for (int k=0;k<MaxPage-1;k++)
{
PrintDC.StartPage();
//把文本文件内容读到CString型szText中
int cy = PrintDC.GetTextExtent("2000/12/31/12:56:23:22").cy ;
int cx = PrintDC.GetTextExtent("2000/12/31/12:56:23:22").cx ;
int cx1 = PrintDC.GetTextExtent("100000.000").cx ;
rect.left = 0;
rect.top = 0;
rect.right = cx;
rect.bottom = cy;

for(int i=posIndex;i<(posIndex+m_LinesPerPage);i++)
{
str = _T("");

for(int j=0;j<rows;j++)
{
str2 = m_GridData.GetItemText(i,j);
str1.Format("%s",str2);
//str += str1;
PrintDC.Rectangle(rect);
PrintDC.DrawText(str1,rect,DT_CENTER);//输出文本到打印机,前两个参数为位置
rect.left =rect.right;
rect.right += cx1;

}
rect.left =0 ;
rect.top +=cy;
rect.right = cx;
rect.bottom +=cy;
}
PrintDC.EndPage();
posIndex+=m_LinesPerPage;
}
PrintDC.EndDoc();
PrintDC.SelectObject(pOldPen);
jude_2002 2007-01-27
  • 打赏
  • 举报
回复
move to(point.x,point.y);
line to(point.x,point.y);
youngwolf 2007-01-27
  • 打赏
  • 举报
回复
你随便找个打印程序看看,其复杂度只有实际做了才知道。
所以,按我以前的经验,凡是问“如何打印”这样的问题,都是得不到解决的。
这个问题就像“如何写一套在线游戏”这个问题一样,太复杂。
你必须先懂一些打印知道,然后自己做,遇到具体的问题,比如“如何获取打印机”等问题,再来问。
希望我的意见能对你有点用!
xiyupiaopiao 2007-01-27
  • 打赏
  • 举报
回复
怎么计算页数,那些坐标把我搞晕了,能给点源码并解释一下吗
typingsoft 2007-01-27
  • 打赏
  • 举报
回复
move to, line to
也简单,也复杂
xiyupiaopiao 2007-01-27
  • 打赏
  • 举报
回复
数据不少,是不太复杂,只要每个数据套上格子就行,能不能给我个例子,考虑,横竖打,分页什么的,
gaotianpeng 2007-01-27
  • 打赏
  • 举报
回复
自已画格子,再填上输出,就像用CDC画格子一样
还好数据不是太多,这样能按自已的要求定制!

16,472

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧