基于对话框的程序如何打印图片?
jpg,bmp的图片(我可以把jpg的读成bmp的)

解决方案 »

  1.   

    在vckbase上见到的,可能是对的,没有试验~!
    void CMyDialog::Print() 
    {
    CDC dc;
    CPrintDialog printDlg(FALSE);
    //利用CPrintDialog 生成打印机设备环境
    if (printDlg.DoModal() == IDCANCEL) // Get printer settings from user 让用户选择打印纸张等
    return;dc.Attach(printDlg.GetPrinterDC()); // Attach a printer DC 让HANDLE连接到dc上
    dc.m_bPrinting = TRUE;CString strTitle; // Get the application title ?
    strTitle.LoadString(AFX_IDS_APP_TITLE);DOCINFO di; // Initialise print document details DOCINFO中有相关的打印信息
    ::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); // 调用你自己定义的初始化功能
    for (UINT page = Info.GetMinPage(); page<Info.GetMaxPage()&& bPrintOK;page++)
    {Info.m_nCurPage = page;
    OnPrint(&dc, &Info); // Call your "Print page" function
    bPrintingOK = (dc.EndPage() > 0); // end page
    }
    OnEndPrinting(&dc, &Info); // 结束打印if (bPrintingOK)
    dc.EndDoc(); // end a print job
    else
    dc.AbortDoc(); // abort job.dc.Detach(); // detach the printer DC
    }