我建了一个基于对话框的程序,我想点击一个按钮然后就将对话框及其上面的所有东西都打印出来我的程序如下:可打印出来的结果成为很小的一块,我想这是由于MM_TEXT模式下
Each logical unit is converted to 1 device pixel的关系,然后我试着改了一些其它模式,调整了坐标点,可是,依然不能实现“所见既所得”的效果,
大家认为该怎么办?能给我一份相关源码吗?找了n多地方,可就是找不到怎么做。。, CRect rect;
GetClientRect(&rect);
CPrintDialog dlgPrint(FALSE,PD_NOPAGENUMS,this);
if (!dlgPrint.GetDefaults ())
return FALSE; CDC dc;
dc.Attach (dlgPrint.GetPrinterDC ()); DOCINFO di;
ZeroMemory(&di,sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);

CPrintInfo pi;
pi.m_rectDraw .SetRect (0,0,rect.Width (),rect.Height ()); StartDoc(dc,&di);
StartPage(dc);

Print(&dc,PRF_OWNED | PRF_CLIENT | PRF_CHILDREN  );
EndPage(dc);
EndDoc(dc); DeleteDC(dc);关键,怎么才能实现屏幕看到的跟打印机打出来的一样大小?

解决方案 »

  1.   

    大小的设置在于设备映射方式的更改,我给你贴一段代码,也是csdn上一个朋友发的,没有具体看,你瞅瞅是否有用:
    ------------------------------------------------------------
    AfxGetApp()->BeginWaitCursor(); UpdateData( true );
    if(m_Method==0) //对角线法
    {
    Calculate( ) ;
    DataSet( INPUT::m_column );
    }
    else// 方格法
    CalculateRect(); mcbCalcStd->GetWindowText(tempstr);
    Grade(tempstr); CDC dc;
    CPrintDialog printDlg(FALSE);
    if(m_printDirect==1)           //是否显示打印对话框
    printDlg.GetDefaults();
    else
    if(printDlg.DoModal()==IDCANCEL)return;  //显示对话框 ,Get printer settings from user

    HDC hdcPrntDC=printDlg.GetPrinterDC();
    ASSERT(hdcPrntDC);
    dc.Attach(hdcPrntDC); // 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;
    CSize PrtSize(Info.m_rectDraw.right-Info.m_rectDraw.left,Info.m_rectDraw.bottom-Info.m_rectDraw.top );
    Info.m_rectDraw.SetRect(0,0, dc.GetDeviceCaps(HORZSIZE), dc.GetDeviceCaps(VERTSIZE)); Info.m_pPD->m_pd.nMaxPage=1; ASSERT(&dc);
    ASSERT(&Info); OnBeginPrinting(&dc, &Info); // Call your "Init printing" funtion {
    dc.StartPage(); // begin new page
    Info.m_nCurPage = 1; if(m_bPRT4Check== FALSE) // 正常打印
    OnPrint(&dc, &Info, 1); // Call your "Print page" function
    else// 打印检修数据
    MyPrint4Check(&dc, &Info); 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.
    GlobalFree(dc.m_hDC);
    dc.Detach();                           // detach the printer DC m_pMyEdit[0][0]->SetFocus();
    m_pMyEdit[0][0]->SetSel((DWORD)0XFF00,TRUE); // m_bSaveAfterPRT; if(m_bPRT4Check==FALSE)
    {
    if(m_bAddAfterPrt && m_CertNo.GetLength())
    {
    StrNumAutoAdd(&m_CertNo);
    UpdateData(FALSE);
    }
    }
    AfxGetApp()->EndWaitCursor();
      

  2.   


    原来是要设置模式。。,更新后的源码如下:CPrintDialog dlgPrint(FALSE,PD_NOPAGENUMS,this);
    if (!dlgPrint.GetDefaults ())
    return FALSE; CDC dc;
    dc.Attach (dlgPrint.GetPrinterDC ()); DOCINFO di;
    ZeroMemory(&di,sizeof(DOCINFO));
    di.cbSize = sizeof(DOCINFO);

    CPrintInfo pi; StartDoc(dc,&di);
    StartPage(dc); dc.SetMapMode(MM_ANISOTROPIC);  
    CSize size = CSize(800, 600);
    dc.SetWindowExt(size);      int xLogPixPerInch = dc.GetDeviceCaps(LOGPIXELSX); 
    int yLogPixPerInch = dc.GetDeviceCaps(LOGPIXELSY);
    long xExt = (long)size.cx * xLogPixPerInch/96 ;
    long yExt = (long)size.cy * yLogPixPerInch/96 ;
    dc.SetViewportExt((int)xExt, (int)yExt); Print(&dc,PRF_OWNED | PRF_CLIENT | PRF_CHILDREN  );
    EndPage(dc);
    EndDoc(dc); DeleteDC(dc);