问题是这样的:
我new了一个新的工程,是单文档的,然后Base Class是CFromView(不是CView哦).然后我在FormView里面放了几个文本框和几个按钮,我怎么把我看到的Formview里的内容打印出来呢?菜单里的"打印"和"打印预览"是打印不到内容的.
是不是要把formview变成图片来打印呢?我下载了一个formview_print例子,"打印预览"可以看到formview里面的内容,但是打印不出来的.
20分在这里:
http://expert.csdn.net/Expert/topic/1851/1851399.xml?temp=.6140711这个是80分。解决问题的我再给她100分。

解决方案 »

  1.   

    我给你一个例子,你留个EMAIL。
      

  2.   

    to yuxiaojie() :
        问题没有解决阿.例子里是通过TextOut,lineto,moveto这样的函数实现把数据传到打印机打印的,不能打印formview看到的东西.由于我的formview里有图片阿,有按钮阿,有很多东西的,所以通过例子的方式是不行的.
        不知道vc有报表吗?报表怎么用的?
      

  3.   

    不知道以下这篇文章能不能帮你;在MFC中打印OpenGL我在很多杂志上看到了OpenGL视的实现,但没有一个是介绍如何打印OpenGL的。 于是,我猜想你巳经有一个实现了的OpenGL视类,但你不能实现打印。  
    class COpenGLView : public CView {
    ...
    protected:
    CDC *m_pDC;
    HGLRC m_hRC;
    ...
    };在你的OnCreate函数中,你将创建下面这些:
    int COpenGLView::OnCreate(LPCREATESTRUCT lpCreateStruct) {
    if (CView::OnCreate (lpCreateStruct) == -1) return (-1);
    m_pDC = new CClientDC (this);
    if (m_pDC == NULL) return (-1);
    //  Set the DC's pixel format...
    if (!SetDCPixelFormat (m_pDC)) return (-1);
    m_hRC = wglCreateContext (m_pDC->GetSafeHdc ());
    if (!wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC)) return (-1);
    glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
    glClearDepth (1.0);
    return (0);
    }注意:在这里我调用了wglMakeCurrent ()函数。有些作者在OnDraw()函数的开始调用这个
    函数,那可能是因为它们的代码没有它就不工作。 wglMakeCurrent ()函数在当前的OpenGL
    窗口创建了一个指定的窗口实例。在一个MDI程序中,带来两个文档的打开,在绘制它们进入
    之前,你需要确认每个视实例创建在它们自己的当前窗口。
    因而,在OnCreate()函数中调用wglMakeCurrent ()函数是不够的 --  另外在第二个视被创
    建之后,在第一个视中的所有OpenGL调用将在第二个视中被得到实施。
    许多作者在他们的视的OnDraw()函数开始部分调用wglMakeCurrent ()
    -- 抵住这种诱惑!这是(粗略)我的OpenGL打印函数COpenGLView::OnPrint():void COpenGLView::OnPrint(CDC* pDC, CPrintInfo* pInfo) {
    //  Let's not worry for now about print preview...
    if (pInfo->m_bPreview) return;
           //  or print a message to preview
    window... UINT CurPage = pInfo->m_nCurPage;
    GLsizei HRes = pDC->GetDeviceCaps(HORZRES);
    GLsizei VRes = pDC->GetDeviceCaps(VERTRES);
    GLsizei HPixelsPerInch = pDC->GetDeviceCaps(LOGPIXELSX);
    GLsizei VPixelsPerInch = pDC->GetDeviceCaps(LOGPIXELSY);
    pDC->SetMapMode (MM_TEXT);
    // m_LMargin, etc are margins, in inches...
    GLint l = (GLint) (m_LMargin*HPixelsPerInch);
    GLint r = (GLint) (m_RMargin*HPixelsPerInch);
    GLint t = (GLint) (m_TMargin*VPixelsPerInch);
    GLint b = (GLint) (m_BMargin*VPixelsPerInch);
    //  Image width and height...
    GLsizei w = HRes - l - r;
    GLsizei h = VRes - t - b;
    //  Probably don't need this...
    int SavedDC = pDC->SaveDC ();
    if (CurPage == 1) {
    //  Save the current OpenGL settings...
    HDC   hDCOld   = wglGetCurrentDC ();
    HGLRC hGLRCOld = wglGetCurrentContext ();
    //  Make the printer the current
    //  OpenGL rendering device...
    HGLRC hGLRCPrinter = wglCreateContext (pDC->GetSafeHdc ());
    BOOL bRet = wglMakeCurrent (pDC->GetSafeHdc (), hGLRCPrinter); ASSERT (bRet);
    glClearColor (1.0f, 1.0f, 1.0f, 1.0f);
    glClearDepth (1.0);
    //  This makes a square image...
    if (w < h) h = w;
    if (h < w) w = h;
    //  This centers the images...
    l = (HRes - w)/2;
    b = (VRes - h)/2;
    //
    glViewport(l, b, w, h);
    OnDraw (pDC);
    //  Go back to the saved OpenGL settings...
    wglMakeCurrent (hDCOld, hGLRCOld);
    wglDeleteContext(hGLRCPrinter);
    }
    //  Probably don't need this...
    if (SavedDC != 0) pDC->RestoreDC (SavedDC);
    }注意:OnPrint ()函数调用OnDraw ()函数。如果在OnDraw ()函数中你调用了wglMakeCurrent
    (),你将不再被打印...你应该重绘这个视!它应当也被注明,在OnBeginPrinting ()
    和OnEndPrinting ()函数中能够做到设置和存储当前的OpenGL设备。为了简单起见,在这里我
    巳经放置了所有代码。
    于是,现在打印OpenGL是简单的。让我们加到绘制...
    为了确售你绘制到了正确的窗口,你需要调用wglMakeCurrent从SOMEWHERE OTHER THAN OnDraw
    ()。 But where? 侯选的是OnActivateView () 与 OnUpdate ()函数。
    我通常重载两这个函数: OnActivateView ()
    和 OnUpdate (),并且在两个函数中我调用 wglMakeCurrent ()。在OnUpdate
    ()函数, 我保存和恢复当前设置在函数的开始和结束(就象在 OnPrint
    ())。在OnActivateView ()函数中这不是必须的。
    void COpenGLView::OnActivateView(BOOL bActivate,
    CView* pActivateView, CView* pDeactiveView) {
    CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
    if (bActivate) {
    wglMakeCurrent (m_pDC->GetSafeHdc (), m_hRC);
    }
    }
    void COpenGLView::OnUpdate (CView* pSender, LPARAM lHint, CObject* pHint) {
    //  Save the current OpenGL settings...
    HDC   hDCOld   = wglGetCurrentDC ();
    HGLRC hGLRCOld = wglGetCurrentContext ();
    //  Make this view the current OpenGL rendering context...
    BOOL bRet = wglMakeCurrent (m_pDC, m_hRC);
    //  Draw!!!
    OnDraw (m_pDC);
    //  Go back to the saved OpenGL settings...
    wglMakeCurrent (hDCOld, hGLRCOld);
    wglDeleteContext(hGLRCPrinter);
    }注:在OnUpdate函数中要返回预先设置。 
      

  4.   

    我做过的,可惜那个是替外面一家单位写的,代码不便给人,我也不想写实例了。
    基本上你可以手工加入一些你没有通过向导添加的程序ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
    ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
    OnPreparePrinting(CPrintInfo* pInfo)
    OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* pInfo)
    OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
    OnPrepareDC(CDC* pDC, CPrintInfo* pInfo) 
    void OnPrint(CDC* pDC, CPrintInfo* pInfo) 
    {
    pDC->SetMapMode( MM_LOENGLISH );
    //8.5*72*20 = 12240
    //11*72*20 = 15840
    //25.4

    if(pInfo->m_nCurPage == 1)
    PrintFirstPage(pDC, pInfo);
    else
    PrintOtherPage(pDC, pInfo);}
    如果用按钮触发打印消息,可以这样做:::PostMessage(::AfxGetApp()->m_pMainWnd->m_hWnd,WM_COMMAND,(WPARAM)ID_FILE_PRINT,0);