大家写打印输出程序时都是怎么写的?我的做法是用Adobe Acrobat 4.0做虚拟打印输出来查看自己写的输出效果,可是后来我才发现到了实际的打印后的效果根模拟的大不一样,它奶奶的,这个垃圾!!!!

解决方案 »

  1.   


    打印的话和在静态控件中绘制原理是一样的,因为WINDOWS通过设备上下文而非直接硬件来绘制,所以获得打印机DC即可。
    参考以下简单代码:
    --------------------------------
    void CMyDlg::OnBtnPrint() 
    {
    // TODO: Add your control notification handler code here CPrintDialog printDlg(false,PD_PAGENUMS | PD_USEDEVMODECOPIES|PD_COLLATE);
    printDlg.m_pd.nMinPage=printDlg.m_pd.nFromPage=nYourFirstPage; //<<----
    printDlg.m_pd.nMaxPage=printDlg.m_pd.nToPage=nYourEndPage; // <<----

    if(AfxGetApp()->DoPrintDialog(&printDlg)!=IDOK) // <<----CWinApp 成员函数,产生打印对话盒。
    {
    AfxMessageBox("放弃打印!");
    return;
    } CDC printDC;
    printDC.Attach(printDlg.m_pd.hDC); printDC.SetMapMode(MM_ANISOTROPIC); // <<---- 
    printDC.SetWindowExt(sizeYourDrawRange.cx;,sizeYourDrawRange.cy);// <<------CSize sizeYourDrawRange
    printDC.SetWindowOrg(0,0); // <<------
    printDC.SetViewportExt(printDC.GetDeviceCaps(HORZRES),printDC.GetDeviceCaps(VERTRES)); // <<----
    printDC.SetViewportOrg(0,0); //<<------ DOCINFO docInfo;
    memset(&docInfo,0,sizeof(DOCINFO));
    docInfo.cbSize=sizeof(DOCINFO);
    docInfo.lpszDocName="your document name";// <<----
    docInfo.lpszOutput=""; <<---- printDC.StartDoc(&docInfo);
    for(int i=nYourFirstPage;i<=nYourFirstPage;i++)
    {
    printDC.StartPage();
    DrawAllContents(..);// <<------ !!!!!! write your draw_code in the function
    printDC.EndPage(); }
    printDC.EndDoc();  printDC.Detach();
    }
      

  2.   

    See the link below, FYI: http://www.codeproject.com/printing/
      

  3.   

    : cbc(逍遥子) :
    你的这段代码在使用时总会有2个GDI对象的泄漏,我也查不出来原因。每次打印时GDI总是在不断的增加2个。
      

  4.   

    我做打印的测试从来都是用Adobe Acrobat 4.0,这个垃圾还不错啊!是不是你哪设置的不对。
      

  5.   

    2个GDI对象的泄漏你怎么查出来得?
      

  6.   

    我用的Acrobat 5.0有两个虚拟打印机:Acrobat Distiller 和 Acrobat PDFWriter。 其中我觉得用PDFWriter比较好。你可以试试,不过首先你要先设置好打印属性
      

  7.   

    我的Acrobat 5.0怎么没有虚拟打印机,版本不一样吗,我的安装文件只有21M,比4的还小