关闭

DataGrid的打印(三)

594人阅读 评论(0) 收藏 举报

//属性情報の印刷
void CAttriPrintDlg::PrintData()
{
 // Create and show the PrintDialog
 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_A3; //A3 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;
 }

 bool bPrintHeader = _chkPrint.GetCheck() == BST_CHECKED;
 bool bPrintFooter = _chkPrint.GetCheck() == BST_CHECKED;
    CPrintHelper helper(&dcPrinter, bPrintHeader, bPrintFooter);

 // 變量初始化:
 int gridRowCount = m_Grid.GetRows();
 int rowPos = 1;
 int page = 1;
 
 while(rowPos < gridRowCount)
 {
  if (dcPrinter.StartPage() < 0)
  {
   MessageBox(_T("ページ処理を開始できません"));
   dcPrinter.AbortDoc();
   return;
  }

  helper.PrintHeader(strTitleText.c_str(), _startYear, _startImage , _endYear, _endImage);
  helper.PrintGridHeader();
  rowPos = helper.PrintPage(m_Grid, rowPos);

  helper.PrintFooter(page);

  dcPrinter.EndPage();

  ++page;
 }
 
 dcPrinter.EndDoc();
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:32378次
    • 积分:528
    • 等级:
    • 排名:千里之外
    • 原创:15篇
    • 转载:0篇
    • 译文:5篇
    • 评论:4条
    最新评论