CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VC/MFC >  界面

list控件内容打印

楼主yahema(悠悠哉)2006-03-12 22:01:01 在 VC/MFC / 界面 提问

我想打印dialog上的list控件的内容,该怎么做呀???请高手指教 问题点数:100、回复次数:7Top

1 楼striking(庸人自扰)回复于 2006-03-12 22:06:51 得分 20

第一步,   看这个   http://www.codeproject.com/printing/#Print+Preview    
  使你的dialog支持打印预览  
   
  第2步,   在OnPrint里面处理,根据list,   先画header,   再画列表。  
   
  网上应该有代码吧Top

2 楼yahema(悠悠哉)回复于 2006-03-12 22:09:32 得分 0

是吗,知道哪里有代码吗,急用中,谢谢提供消息Top

3 楼striking(庸人自扰)回复于 2006-03-12 22:24:40 得分 0

你会drawtext吗?   如果会,   就自己画吧。Top

4 楼striking(庸人自扰)回复于 2006-03-12 22:47:08 得分 20

参考这个http://www.codeproject.com/listctrl/listprintdemo.aspTop

5 楼ianok(再菜我也要up出個星來)回复于 2006-03-14 10:06:52 得分 40

CPrintDialog   dlg(TRUE,   PD_ALLPAGES|PD_ALLPAGES|PD_NOPAGENUMS,   NULL);    
  PRINTDLG   *pPrintDlg   =   &dlg.m_pd;    
  AfxGetApp()->GetPrinterDeviceDefaults(pPrintDlg);    
  DEVMODE*   lpDevMode   =   (DEVMODE*)::GlobalLock(pPrintDlg->hDevMode);    
  ::GlobalUnlock(pPrintDlg->hDevMode);    
  lpDevMode->dmPaperSize   =   DMPAPER_A4;   //A4   297   x   420   mm  
  lpDevMode->dmOrientation   =   DMORIENT_LANDSCAPE;   //橫向  
   
  if(dlg.DoModal()   ==   IDCANCEL)  
  return;  
   
  //   create   a   CDC   and   attach   it   to   the   default   printer  
  CDC   dcPrinter;  
  dcPrinter.Attach(dlg.CreatePrinterDC());  
   
  //   initialize   DOCINFO  
  DOCINFO   docinfo;  
  memset(&docinfo,   0,   sizeof(docinfo));  
  docinfo.cbSize   =   sizeof(docinfo);  
  CString   title;  
  GetWindowText(title);  
  docinfo.lpszDocName   =   title;  
   
  //   if   it   fails,   complain   and   exit   gracefully  
  if   (dcPrinter.StartDoc(&docinfo)   <   0)  
  {  
  MessageBox(_T("プリンタは初期化できません"));  
  return;  
  }  
    CPrintHelper   helper(&dcPrinter);  
  //   變量初始化:行數,頁數,當前行,當前頁  
  int   lineNumber   =   m_Grid.GetRows()   -   1;  
  int   pageNumber   =   (int)   ceil(   (double)lineNumber/helper.LinesPerPage());  
  int   line   =   1;  
  int   page   =   1;  
   
  while   (page   <=   pageNumber)  
  {  
  if   (dcPrinter.StartPage()   <   0)  
  {  
  MessageBox(_T("ページ処理は開始できません"));  
  dcPrinter.AbortDoc();  
  return;  
  }  
   
  helper.PrintHeader(strTitleText.c_str(),   _startYear,   _startImage   ,   _endYear,   _endImage);  
  helper.PrintPage(m_Grid,   line);  
  helper.PrintFooter(page,   pageNumber);  
  dcPrinter.EndPage();  
   
  ++page;  
  line   +=   helper.LinesPerPage();  
  }  
   
  dcPrinter.EndDoc();Top

6 楼TianChong(*︿_︿* ○Ооo○泡泡oо㊣VC高手群:2997669)回复于 2006-03-14 12:15:18 得分 20

The   OnBeginPrinting   function   prepares   printer   fonts   and   calculates   paper,   page,   header,   footer   and   body   rectangles.  
   
  void   CListDemoViewPrint::OnBeginPrinting(CDC*   pDC,   CPrintInfo*   pInfo)  
  {        
        //   Create   fonts  
        m_pFontHeader   =   CreateFont(pDC,_T("Arial"),   12,   FW_BOLD);  
        m_pFontFooter   =   CreateFont(pDC,_T("Arial"),   10);  
        m_pFontColumn   =   CreateFont(pDC,_T("Arial"),   9,   FW_BOLD);  
        m_pFontBody       =   CreateFont(pDC,_T("Times   New   Roman"),   10);  
   
        //   Calculate   character   size  
        m_CharSizeHeader   =   GetCharSize(pDC,   m_pFontHeader);  
        m_CharSizeFooter   =   GetCharSize(pDC,   m_pFontFooter);  
        m_CharSizeBody       =   GetCharSize(pDC,   m_pFontBody);  
   
        //   Prepare   layout    
        m_rectPaper     =   GetPaperRect(pDC);  
        m_rectPage       =   GetPageRect();  
        m_rectHeader   =   GetHeaderRect();  
        ...  
        m_RatioX   =   GetTextRatioX(pDC);        
        ...  
  }  
  Character   sizes   are   used   later   to   calculate   header   and   footer   vertical   height,   body   character   size   is   used   to   calculate   row   (cell)   height,   number   of   rows   per   page   and   horizontal   X   ratio   to   adjust   column   width.  
   
  Character   size   is   calculated   simply   by   selecting   font   and   getting   sample   string   extent   as   follows.  
   
  CSize   CListDemoViewPrint::GetCharSize(CDC*   pDC,   CFont*   pFont)  
  {  
        CFont   *pOldFont   =   pDC->SelectObject(pFont);  
        CSize   charSize   =   pDC->GetTextExtent(_T("abcdefghijkl  
                mnopqrstuvwxyzABCDEFGHIJKLMNOPQRSATUVWXYZ"),52);  
        charSize.cx   /=   52;  
        pDC->SelectObject(pOldFont);  
        return   charSize;  
  }  
  Horizontal   text   ratio   is   calculated   using   body   font   character   size   and   list   control   average   character   size.  
   
  double   CListDemoViewPrint::GetTextRatioX(CDC*   pDC)  
  {  
        ASSERT(pDC   !=   NULL);  
        ASSERT(m_pListCtrl);  
        CDC*   pCurrentDC   =   m_pListCtrl->GetDC();  
        TEXTMETRIC   tmSrc;  
        pCurrentDC->GetTextMetrics(&tmSrc);  
        m_pListCtrl->ReleaseDC(pCurrentDC);  
        return   ((double)m_CharSizeBody.cx)   /   ((double)tmSrc.tmAveCharWidth);  
  }  
  Using   the   code  
  Add   the   CListDemoViewPrint   class   member   to   your   CListView   derived   class.  
   
  class   CListDemoView   :   public   CListView  
  {  
      ...  
      CListDemoViewPrint   m_Print;  
  };  
  Add   the   following   printing   functions   to   your   class.  
   
  BOOL   CListDemoView::OnPreparePrinting(CPrintInfo*   pInfo)  
  {  
        m_Print.OnPreparePrinting(pInfo);  
        return   DoPreparePrinting(pInfo);  
  }  
   
  void   CListDemoView::OnBeginPrinting(CDC*   pDC,   CPrintInfo*   pInfo)  
  {        
        m_Print.OnBeginPrinting(pDC,   pInfo);  
  }  
   
  void   CListDemoView::OnPrint(CDC*   pDC,   CPrintInfo*   pInfo)    
  {  
        m_Print.OnPrint(pDC,   pInfo);  
  }  
   
  void   CListDemoView::OnEndPrinting(CDC*   pDC,   CPrintInfo*   pInfo)  
  {  
        m_Print.OnEndPrinting(pDC,   pInfo);  
  }  
  Andres   Kaasik  
  Top

7 楼lizifong(scorrt)回复于 2006-03-14 20:22:13 得分 0

markTop

相关问题

  • >>> FastReport如何动态控件打印的内容(指文本打印内容)??
  • 如何在调用commonDialog控件后,打印label和text内容?
  • 怎样打印PictureBox控件中的内容?
  • 如何用VB打印控件中的内容?
  • 如何将picture控件中的内容输出到打印机?
  • 请问如何打印TreeView控件的内容?
  • 如保打印窗体上的MSFlexGrid控件中的内容!
  • 如何实现datagrid 控件中的内容打印
  • printer对象打印控制控件内容top的问题
  • 如何打印出MsFlexGrid控件中的内容?

关键词

  • 打印
  • docinfo
  • pprintdlg
  • clistdemoviewprint
  • pcurrentdc
  • tmsrc
  • plistctrl
  • dcprinter
  • charsize
  • dlg

得分解答快速导航

  • 帖主:yahema
  • striking
  • striking
  • ianok
  • TianChong

相关链接

  • Visual C++类图书
  • Visual C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo