要在对话框中实现打印,必须得到打印机DC,请问如何得到?

解决方案 »

  1.   

    http://www.codeguru.com/printing/printing_wo_docview.shtml
    Printing without the Document/View framework    CDC dc;
        CPrintDialog printDlg(FALSE);    if (printDlg.DoModal() == IDCANCEL)         // Get printer settings from user
            return;    dc.Attach(printDlg.GetPrinterDC());         // Attach a printer DC
      

  2.   

    http://www.codeguru.com/printing/printing_wo_docview.shtml
    http://www.codeguru.com/printing/printing_class_library.shtml
      

  3.   

    我的几个打印函数如下,根本没有调用打印机,请问是何原因?void CDialogPrintDlg::OnBeginPrinting(CDC *pDC, CPrintInfo *pInfo)
    {
        pInfo->SetMinPage(1);
    pInfo->SetMaxPage(1);
    }void CDialogPrintDlg::OnEndPrinting(CDC *pDC, CPrintInfo *pInfo)
    {}void CDialogPrintDlg::OnStartPrint() 
    {
    // TODO: Add your control notification handler code here
        CDC dc;
        CPrintDialog printDlg(FALSE);    if (printDlg.DoModal() == IDCANCEL)// Get printer settings fromuser
            return;    dc.Attach(printDlg.GetPrinterDC());       // Attach a printer DC
        dc.m_bPrinting = TRUE;    CString strTitle;                  // Get the application title
        strTitle.LoadString(AFX_IDS_APP_TITLE);    DOCINFO di;               // Initialise print document details
        ::ZeroMemory (&di, sizeof (DOCINFO));
        di.cbSize = sizeof (DOCINFO);
        di.lpszDocName = strTitle;    BOOL bPrintingOK = dc.StartDoc(&di);   // Begin a new print job    // Get the printing extents and store in the m_rectDraw field of a 
        // CPrintInfo object
        CPrintInfo Info;
        Info.m_rectDraw.SetRect(0,0, 
                                dc.GetDeviceCaps(HORZRES), 
                                dc.GetDeviceCaps(VERTRES));    OnBeginPrinting(&dc, &Info);                // Call your "Init printing" funtion
        for (UINT page = Info.GetMinPage(); 
             page <= Info.GetMaxPage() && bPrintingOK; 
             page++)
        {
            dc.StartPage();                         // begin new page
            Info.m_nCurPage = page;
            OnPrint(&dc, &Info);                    // Call your "Print page" function
            bPrintingOK = (dc.EndPage() > 0);       // end page
        }
        OnEndPrinting(&dc, &Info);                  // Call your "Clean up" funtion    if (bPrintingOK)
            dc.EndDoc();                            // end a print job
        else
            dc.AbortDoc();                          // abort job.    dc.Detach();
    }void CDialogPrintDlg::OnPrint(CDC *pDC, CPrintInfo *pInfo)
    {
        OnPaint();
    }
      

  4.   

    我没有打印类啊。。在按纽上单击时直接就调用onpaint了。
      

  5.   

    说错了,直接调用OnStartPrint,在OnStartPrint中调用onprint