下面是我在View中重载的打印函数,已经实现打印预览了.但是在打印预览中点击打印按钮却并没有出现打印提示.如果方便,哪位高手给个可以预览打印的例子,网上那几个的我已经找过了,都实现不了.
void CRegCodeMgrView::OnMyPrintPreview()
{
GetParent()->ShowWindow(SW_SHOWMAXIMIZED);
m_bPrint=FALSE;
CHHView::OnFilePrintPreview();
}
BOOL CRegCodeMgrView::OnPreparePrinting(CPrintInfo* pInfo) 
{
if(DoPreparePrinting(pInfo))
return TRUE;
else
{
GetParent()->DestroyWindow();
return FALSE;
}
}void CRegCodeMgrView::OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
CHHView::OnBeginPrinting(pDC, pInfo);
CPrintFrame *pFrame =(CPrintFrame *)GetParent();
pFrame->m_pCallerDlg->SendMessage(WM_BEGIN_PRINTING,(WPARAM) pDC, (LPARAM) pInfo);
}
void CRegCodeMgrView::OnEndPrinting(CDC* pDC, CPrintInfo* pInfo) 
{
CHHView::OnEndPrinting(pDC, pInfo);
CPrintFrame *pFrame =(CPrintFrame *)GetParent();
pFrame->m_pCallerDlg->SendMessage(WM_END_PRINTING,(WPARAM) pDC, (LPARAM) pInfo);
if(m_bPrint) //直接打印,不是预览
GetParent()->DestroyWindow();
}void CRegCodeMgrView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
{
CPrintFrame *pFrame =(CPrintFrame *)GetParent();
pFrame->m_pCallerDlg->SendMessage(WM_MY_PRINT,(WPARAM) pDC, (LPARAM) pInfo) ;
}
void CRegCodeMgrView::OnEndPrintPreview(CDC* pDC, CPrintInfo* pInfo, POINT point, CPreviewView* pView) 
{
CHHView::OnEndPrintPreview(pDC, pInfo, point, pView);
GetParent()->PostMessage (WM_CLOSE);

}

解决方案 »

  1.   

    楼上的不一定对,但是我感觉好象m_bPrint=FALSE
      

  2.   

    已经试 过了,改为FALSE时打印报错!有高手给指点指点了!!!
      

  3.   

    bool CReportDlg::PrintImageRpt()
    {
    if (m_NowReportNO==m_TotalReportNum)
    OnButtonSave();
    CString szPrinterName,TmpStr;
    INT i,DPI,x;
    CDC prndc;
    float VRatio,HRatio,DPIScale;
    INT nPrnPixelX,nPrnPixelY,nPrnWidth,nPrnHeight;
    CRect tmpRect; CPrintDialog printdlg(true);
    if(printdlg.DoModal()!=IDOK){                                                                                                                                                                
    return(false);
    }

    DEVMODE prndevmode;
    prndevmode=*(printdlg.GetDevMode());
    CString portname=printdlg.GetPortName();
    CString drivername=printdlg.GetDriverName();
    szPrinterName=printdlg.GetDeviceName();
    BOOL rtn=prndc.CreateDC(drivername,szPrinterName,portname,NULL);
    if(rtn==0){
    AfxMessageBox("系统安装"+szPrinterName+"驱动程序存在问题!\n打印操作失败!",MB_ICONSTOP|MB_OK);
    return(false);
    }

    //BOOL rtn=prndc.CreateDC("HP","HP LaserJet 6L (Simpl (Copy 2)","LPT1",NULL);
    if(prndc.GetDeviceCaps(TECHNOLOGY)!=DT_RASPRINTER){
    AfxMessageBox("系统打印机出现故障!\n请与系统开发商联系!",MB_ICONQUESTION|MB_OK);
    return(false);
    }
    //HORZSIZE   Width of the physical display (in millimeters).
    //VERTSIZE   Height of the physical display (in millimeters).
    //HORZRES   Width of the display (in pixels).
    //VERTRES   Height of the display (in raster lines).
    //LOGPIXELSX   Number of pixels per logical inch along the display width.
    //LOGPIXELSY   Number of pixels per logical inch along the display height.
    //BITSPIXEL   Number of adjacent color bits for each pixel.
    //PLANES   Number of color planes.
    //NUMBRUSHES   Number of device-specific brushes.
    //NUMPENS   Number of device-specific pens.
    //NUMFONTS   Number of device-specific fonts.
    //NUMCOLORS   Number of entries in the device's color table.
    //ASPECTX   Relative width of a device pixel as used for line drawing.
    //ASPECTY   Relative height of a device pixel as used for line drawing.
    //ASPECTXY   Diagonal width of the device pixel as used for line drawing.
    //PDEVICESIZE   Size of the PDEVICE internal data structure.
    //CLIPCAPS   Clipping capabilities of the device. It can be one of the following: nPrnPixelX=prndc.GetDeviceCaps(HORZRES);//
    nPrnPixelY=prndc.GetDeviceCaps(VERTRES);
    nPrnWidth=prndc.GetDeviceCaps(HORZSIZE);
    nPrnHeight=prndc.GetDeviceCaps(VERTSIZE);
    i=prndc.GetDeviceCaps(LOGPIXELSX);
    HRatio=(float)(prndc.GetDeviceCaps(HORZRES))/(float)254;
    i=prndc.GetDeviceCaps(LOGPIXELSY);
    DPI=i;
    VRatio=(float)(prndc.GetDeviceCaps(VERTRES))/(float)254;
    HRatio=VRatio;
    DPIScale=(float)((double)DPI/600.0);
    if(DPI==600) DPIScale=1.0;
    i=prndc.GetDeviceCaps(HORZSIZE);
    i=prndc.GetDeviceCaps(VERTSIZE);

    DOCINFO docinfo;//打印任务中文档的输入输出信息。
      

  4.   

    docinfo.lpszDocName="放射科X线诊断报告";
    docinfo.lpszOutput=NULL;
    docinfo.cbSize=sizeof(DOCINFO);
    docinfo.lpszDatatype="char";
    docinfo.fwType=0; i=prndc.StartDoc(&docinfo);
    i=prndc.StartPage();

    CFont TitleFont,PromptFont,font1;
    CPen  pen(PS_SOLID,5,RGB(0,0,0));
    TitleFont.CreateFont((int)(-160*DPIScale),0,0,0,400,FALSE,FALSE,0,
    ANSI_CHARSET,OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
    DEFAULT_PITCH|FF_SWISS,"黑体");
    PromptFont.CreateFont((int)(-120*DPIScale),0,0,0,400,FALSE,FALSE,0,
    ANSI_CHARSET,OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
    DEFAULT_PITCH|FF_SWISS,"宋体");
    font1.CreateFont((int)(-100*DPIScale),0,0,0,400,FALSE,FALSE,0,
    ANSI_CHARSET,OUT_DEFAULT_PRECIS,
    CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
    DEFAULT_PITCH|FF_SWISS,"宋体");

    CFont *pOldFont=(CFont *)prndc.SelectObject(&TitleFont);
    CPen *pOldPen=(CPen *)prndc.SelectObject(&pen);

    TEXTMETRIC tm;
    prndc.GetTextMetrics(&tm);

    CString m_szHospitalName="深圳市妇幼保健院";//医院名称

    tmpRect.SetRect(0,(int)(10*VRatio),nPrnPixelX,(int)(17*VRatio));
    prndc.DrawText(m_szHospitalName,-1,tmpRect,DT_CENTER); tmpRect.SetRect(0,int(17*VRatio),nPrnPixelX,int(24*VRatio));
    prndc.SelectObject(&PromptFont);
    m_szHospitalName="放射科X线诊断报告";
    prndc.DrawText(m_szHospitalName,-1,tmpRect,DT_CENTER); int RptRectLeft=10,RptRectTop=24,RptRectRight=170,RptRectButtom=235; prndc.Rectangle((int)(RptRectLeft*HRatio),(int)(RptRectTop*VRatio),(int)(RptRectRight*HRatio),(int)(RptRectButtom*VRatio)); prndc.SelectObject(&pen);
    prndc.GetTextMetrics(&tm);

    prndc.SelectObject(&font1);//  打印病人信息
    int vline[9]={10,25,45,55,80,95,125,140,170};
    for(x=1;x<8;x++)
    {
    prndc.MoveTo(int(vline[x]*HRatio),(int)(RptRectTop*VRatio));
    prndc.LineTo(int(vline[x]*HRatio),(int)((RptRectTop+14)*VRatio));
    }
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectTop+7)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectTop+7)*VRatio));
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectTop+14)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectTop+14)*VRatio)); CString OutStr1[8]={"姓名","张山","性别","男","门诊号","957849","X线号","4754893"}; 
    CString OutStr2[8]={"部位","胸部","年龄","23","住院号","984322","床号","93"}; GetDlgItem(IDC_LABEL_PATNAME)->GetWindowText(OutStr1[1]);
    GetDlgItem(IDC_LABEL_PATSEX)->GetWindowText(OutStr1[3]);
    GetDlgItem(IDC_LABEL_DIAGNO)->GetWindowText(OutStr1[5]);
    GetDlgItem(IDC_LABEL_XRAYNO)->GetWindowText(OutStr1[7]);
    GetDlgItem(IDC_LABEL_CHECKPART)->GetWindowText(OutStr2[1]);
    m_EditPatAge.GetWindowText(OutStr2[3]);
    GetDlgItem(IDC_LABEL_INHOSPITALNO)->GetWindowText(OutStr2[5]);
    GetDlgItem(IDC_LABEL_BEDNO)->GetWindowText(OutStr2[7]);
    for(x=0;x<8;x++)
    {
    tmpRect.SetRect(int(vline[x]*HRatio),(int)(RptRectTop*VRatio),int(vline[x+1]*HRatio),(int)((RptRectTop+7)*VRatio));
    prndc.DrawText(OutStr1[x],-1,tmpRect,DT_CENTER|DT_SINGLELINE|DT_VCENTER); tmpRect.SetRect(int(vline[x]*HRatio),(int)((RptRectTop+7)*VRatio),int(vline[x+1]*HRatio),(int)((RptRectTop+14)*VRatio));
    prndc.DrawText(OutStr2[x],-1,tmpRect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
    } if (m_FluoroCheckType) // 透视报告
    {
    //  打印图像
    HDRAWDIB PRNHDD=DrawDibOpen();
    HDC Hdc=prndc.GetSafeHdc();
    if (m_ReportImageFrame[1].m_XDib.IsEmpty())//单张图
    {
    CSize PrnImgSize((int)(120*VRatio),(int)(120*VRatio));
    m_ReportImageFrame[0].m_XDib.DispXRayImage(PRNHDD,Hdc,CPoint((int)((RptRectLeft+20)*VRatio),(int)((RptRectTop+17)*VRatio)),PrnImgSize);
    if(pRptOvly[0])
    {
    pRptOvly[0]->Stretch(&prndc,false,false,(float)PrnImgSize.cx/576.0,(float)PrnImgSize.cy/576.0,(int)((RptRectLeft+20)*VRatio),(int)((RptRectTop+17)*VRatio));
    }
    }
    else//四分格打印
    {
    CSize PrnImgSize((int)(60*VRatio),(int)(60*VRatio));
    m_ReportImageFrame[0].m_XDib.DispXRayImage(PRNHDD,Hdc,CPoint((int)((RptRectLeft+19)*VRatio),(int)((RptRectTop+16)*VRatio)),PrnImgSize);
    pRptOvly[0]->Stretch(&prndc,false,false,(float)PrnImgSize.cx/576.0,(float)PrnImgSize.cy/576.0,(int)((RptRectLeft+19)*VRatio),(int)((RptRectTop+16)*VRatio));
    m_ReportImageFrame[1].m_XDib.DispXRayImage(PRNHDD,Hdc,CPoint((int)((RptRectLeft+19+61)*VRatio),(int)((RptRectTop+16)*VRatio)),PrnImgSize);
    pRptOvly[1]->Stretch(&prndc,false,false,(float)PrnImgSize.cx/576.0,(float)PrnImgSize.cy/576.0,(int)((RptRectLeft+19+61)*VRatio),(int)((RptRectTop+16)*VRatio));
    m_ReportImageFrame[2].m_XDib.DispXRayImage(PRNHDD,Hdc,CPoint((int)((RptRectLeft+19)*VRatio),(int)((RptRectTop+16+61)*VRatio)),PrnImgSize);
    pRptOvly[2]->Stretch(&prndc,false,false,(float)PrnImgSize.cx/576.0,(float)PrnImgSize.cy/576.0,(int)((RptRectLeft+19)*VRatio),(int)((RptRectTop+16+61)*VRatio));
    m_ReportImageFrame[3].m_XDib.DispXRayImage(PRNHDD,Hdc,CPoint((int)((RptRectLeft+19+61)*VRatio),(int)((RptRectTop+16+61)*VRatio)),PrnImgSize);
    pRptOvly[3]->Stretch(&prndc,false,false,(float)PrnImgSize.cx/576.0,(float)PrnImgSize.cy/576.0,(int)((RptRectLeft+19+61)*VRatio),(int)((RptRectTop+16+61)*VRatio));
    }
    DrawDibClose(PRNHDD);

    prndc.SetTextColor(0);
    //  现象描述
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectTop+140)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectTop+140)*VRatio));
    prndc.MoveTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+140)*VRatio));
    prndc.LineTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+175)*VRatio));
    tmpRect.SetRect((int)(RptRectLeft*HRatio),(int)((RptRectTop+150)*VRatio),(int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+175)*VRatio));
    prndc.DrawText("现\n象\n描\n述",-1,tmpRect,DT_CENTER);
    CString szDiscribe;
    m_EditDiscribe.GetWindowText(szDiscribe);
    tmpRect.SetRect((int)((RptRectLeft+9)*HRatio),(int)((RptRectTop+141)*VRatio),(int)((RptRectRight-1)*HRatio),(int)((RptRectTop+165)*VRatio));
    prndc.DrawText(szDiscribe,-1,tmpRect,DT_LEFT|DT_WORDBREAK); // 诊断意见
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectTop+175)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectTop+175)*VRatio));
    prndc.MoveTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+175)*VRatio));
    prndc.LineTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+197)*VRatio));
    tmpRect.SetRect((int)(RptRectLeft*HRatio),(int)((RptRectTop+178)*VRatio),(int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+197)*VRatio));
    prndc.DrawText("诊\n断\n意\n见",-1,tmpRect,DT_CENTER);
    CString szAdvice;
    m_EditAdvice.GetWindowText(szAdvice);
    tmpRect.SetRect((int)((RptRectLeft+9)*HRatio),(int)((RptRectTop+176)*VRatio),(int)((RptRectRight-1)*HRatio),(int)((RptRectTop+197)*VRatio));
    prndc.DrawText(szAdvice,-1,tmpRect,DT_LEFT|DT_WORDBREAK);
    }
    else // 拍片报告
      

  5.   

    {
    //  现象描述
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectTop+14)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectTop+14)*VRatio));
    prndc.MoveTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+14)*VRatio));
    prndc.LineTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+130)*VRatio));
    tmpRect.SetRect((int)(RptRectLeft*HRatio),(int)((RptRectTop+55)*VRatio),(int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+129)*VRatio));
    prndc.DrawText("现\n象\n描\n述",-1,tmpRect,DT_CENTER);
    CString szDiscribe;
    m_EditDiscribe.GetWindowText(szDiscribe);
    tmpRect.SetRect((int)((RptRectLeft+9)*HRatio),(int)((RptRectTop+15)*VRatio),(int)((RptRectRight-1)*HRatio),(int)((RptRectTop+129)*VRatio));
    prndc.DrawText(szDiscribe,-1,tmpRect,DT_LEFT|DT_WORDBREAK); // 诊断意见
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectTop+130)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectTop+130)*VRatio));
    prndc.MoveTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+130)*VRatio));
    prndc.LineTo((int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+197)*VRatio));
    tmpRect.SetRect((int)(RptRectLeft*HRatio),(int)((RptRectTop+160)*VRatio),(int)((RptRectLeft+8)*HRatio),(int)((RptRectTop+197)*VRatio));
    prndc.DrawText("诊\n断\n意\n见",-1,tmpRect,DT_CENTER);
    CString szAdvice;
    m_EditAdvice.GetWindowText(szAdvice);
    tmpRect.SetRect((int)((RptRectLeft+9)*HRatio),(int)((RptRectTop+131)*VRatio),(int)((RptRectRight-1)*HRatio),(int)((RptRectTop+196)*VRatio));
    prndc.DrawText(szAdvice,-1,tmpRect,DT_LEFT|DT_WORDBREAK);
    }//  表下方的时间、医生等  
    int vline2[7]={10,30,60,80,115,135,170};
    for(x=1;x<6;x++)
    {
    prndc.MoveTo(int(vline2[x]*HRatio),(int)(RptRectButtom*VRatio));
    prndc.LineTo(int(vline2[x]*HRatio),(int)((RptRectButtom-14)*VRatio));
    }
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectButtom-7)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectButtom-7)*VRatio));
    prndc.MoveTo((int)(RptRectLeft*HRatio),(int)((RptRectButtom-14)*VRatio));
    prndc.LineTo((int)(RptRectRight*HRatio),(int)((RptRectButtom-14)*VRatio));

    CString OutStr3[6]={"送诊科室","外科","X线医生","李医生","(签字)",""}; 
    CString OutStr4[6]={"主治医生","张医生","拍片时间","2003年10月10日","诊断时间","2003年11月11日"}; GetDlgItem(IDC_LABEL_DEPART)->GetWindowText(OutStr3[1]);
    m_XRayDrName.GetWindowText(OutStr3[3]);
    GetDlgItem(IDC_LABEL_DRNAME)->GetWindowText(OutStr4[1]);
    GetDlgItem(IDC_LABEL_CHECKDATE)->GetWindowText(OutStr4[3]);
    GetDlgItem(IDC_LABEL_REPORTDATE)->GetWindowText(OutStr4[5]);
    for(x=0;x<6;x++)
    {
    tmpRect.SetRect(int(vline2[x]*HRatio),(int)((RptRectButtom-7)*VRatio),int(vline2[x+1]*HRatio),(int)(RptRectButtom*VRatio));
    prndc.DrawText(OutStr4[x],-1,tmpRect,DT_CENTER|DT_SINGLELINE|DT_VCENTER); tmpRect.SetRect(int(vline2[x]*HRatio),(int)((RptRectButtom-14)*VRatio),int(vline2[x+1]*HRatio),(int)((RptRectButtom-7)*VRatio));
    prndc.DrawText(OutStr3[x],-1,tmpRect,DT_CENTER|DT_SINGLELINE|DT_VCENTER);
    } CTime curTime=CTime::GetCurrentTime();
    TmpStr.Format("打印时间:%d年%02d月%02d日",curTime.GetYear(),curTime.GetMonth(),curTime.GetDay());
    tmpRect.SetRect(int(RptRectLeft*HRatio),int((RptRectButtom+2)*VRatio),int(RptRectRight*HRatio),int((RptRectButtom+9)*VRatio));
    prndc.DrawText(TmpStr,-1,tmpRect,DT_RIGHT);
    prndc.DrawText("注:本报告只提供参考性意见",-1,tmpRect,DT_LEFT); prndc.SelectObject(pOldFont);
    prndc.SelectObject(pOldPen);
    if(prndc.EndPage()==SP_ERROR){
    AfxMessageBox("打印失败");
    }

    prndc.EndDoc();
    return(1);