Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Blank printout to printer

Blank printout to printer

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcom
15 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Joe Smith IX

    Hi, Yes, following the article number 4, I use CreaterPrinterDC and initialize m_rectDraw and m_nCurPage. I do not change the page orientation nor the MAPMODE (I figure I can deal with this later IF the printed results is incorrect, yes?) Regards, jsix

    N Offline
    N Offline
    Nelek
    wrote on last edited by
    #4

    Orientation should be portrait by default, but depending on MAPMODE you can probably see nothing printed. Take a look into GetDeviceCaps and pInfo. Printing is not so easy. I needed between 3 and 4 weeks to get output in three different printers correctly.

    Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

    J 1 Reply Last reply
    0
    • N Nelek

      Orientation should be portrait by default, but depending on MAPMODE you can probably see nothing printed. Take a look into GetDeviceCaps and pInfo. Printing is not so easy. I needed between 3 and 4 weeks to get output in three different printers correctly.

      Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

      J Offline
      J Offline
      Joe Smith IX
      wrote on last edited by
      #5

      Thanks for the tips, but actually I once trying inserting one DrawText function and it printed out the text fine, but the report was not printed. So I am guessing that the parameter for the printer were correct already and problem is somewhere else. Did you try compiling and printing my report? (I know printing is not easy. But I want to have something printed out first, correctly or not, before experimenting/learning other parameters).

      N 1 Reply Last reply
      0
      • J Joe Smith IX

        Thanks for the tips, but actually I once trying inserting one DrawText function and it printed out the text fine, but the report was not printed. So I am guessing that the parameter for the printer were correct already and problem is somewhere else. Did you try compiling and printing my report? (I know printing is not easy. But I want to have something printed out first, correctly or not, before experimenting/learning other parameters).

        N Offline
        N Offline
        Nelek
        wrote on last edited by
        #6

        I don't have VC++ installed in this laptop so it is difficult for me to compile/debug. I am just answering by heart (I can have errors). I have taken a look into your code and...

        bPrintingOK &= dc.StartDoc(&docinfo);
        bPrintingOK &= dc.StartPage();
        ((CReportView*)theApp.m_pReportView)->OnPrint(&dc, &Info);
        //
        //
        bPrintingOK &= dc.EndPage();
        ((CReportView*)theApp.m_pReportView)->OnEndPrinting(&dc, &Info);

        Why are you mixing a dialog to set printing parameters but then printing from your other view? Wouldn't be easier to set parameters and print directly there? Chris' article is to print within a dialog. So, as you said, using a DrawText in the dialog prints it works. Sending DCs and pInfos from one place to another is not so good idea. I think the problem can be there

        Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

        J 1 Reply Last reply
        0
        • N Nelek

          I don't have VC++ installed in this laptop so it is difficult for me to compile/debug. I am just answering by heart (I can have errors). I have taken a look into your code and...

          bPrintingOK &= dc.StartDoc(&docinfo);
          bPrintingOK &= dc.StartPage();
          ((CReportView*)theApp.m_pReportView)->OnPrint(&dc, &Info);
          //
          //
          bPrintingOK &= dc.EndPage();
          ((CReportView*)theApp.m_pReportView)->OnEndPrinting(&dc, &Info);

          Why are you mixing a dialog to set printing parameters but then printing from your other view? Wouldn't be easier to set parameters and print directly there? Chris' article is to print within a dialog. So, as you said, using a DrawText in the dialog prints it works. Sending DCs and pInfos from one place to another is not so good idea. I think the problem can be there

          Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

          J Offline
          J Offline
          Joe Smith IX
          wrote on last edited by
          #7

          Ah, so you can't compile it now, I see. Could you please try it later? In Chris' article, it shows that the parameters are set from CMyDialog::Print() and pass them to the view class.

          OnPrint(&dc, &Info); // Call your "Print page" function

          Anyway, I tried setting/calling the print dialog from within the view, same result: empty page.

          N 1 Reply Last reply
          0
          • J Joe Smith IX

            Ah, so you can't compile it now, I see. Could you please try it later? In Chris' article, it shows that the parameters are set from CMyDialog::Print() and pass them to the view class.

            OnPrint(&dc, &Info); // Call your "Print page" function

            Anyway, I tried setting/calling the print dialog from within the view, same result: empty page.

            N Offline
            N Offline
            Nelek
            wrote on last edited by
            #8

            My private laptop is broken and in this (work) I have not the VC++, I won't be able to compile. On the other hand... Quote from the article: In order to keep the MFC Doc/View feel I recomend providing helper callback functions OnBeginPrinting, OnEndPrinting and OnPrint similar to the CView versions. A CDC and a CPrintInfo object is passed into each of these functions. You will have to provide these functions yourself. Read carefully the introduction. These functions are to be made into the dialog. Other thing that you can make is to track down your code when you call the OnPrint of your recport view, and see if the pDC there is getting the right values (think that I guess is your problem). What are you using your ReportViewDlg for?

            Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

            J 1 Reply Last reply
            0
            • N Nelek

              My private laptop is broken and in this (work) I have not the VC++, I won't be able to compile. On the other hand... Quote from the article: In order to keep the MFC Doc/View feel I recomend providing helper callback functions OnBeginPrinting, OnEndPrinting and OnPrint similar to the CView versions. A CDC and a CPrintInfo object is passed into each of these functions. You will have to provide these functions yourself. Read carefully the introduction. These functions are to be made into the dialog. Other thing that you can make is to track down your code when you call the OnPrint of your recport view, and see if the pDC there is getting the right values (think that I guess is your problem). What are you using your ReportViewDlg for?

              Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

              J Offline
              J Offline
              Joe Smith IX
              wrote on last edited by
              #9

              I use the ReportViewDlg to show the report in the custom control (see number 3 in my initial post). I think the pDC is correct. Here is the function where I inserted the DrawText that prints OK.

              void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
              {
              CReportDoc* pDoc = GetDocument();
              ASSERT_VALID(pDoc);
              pDoc->Draw(pDC); // This does not print anything

              CRect printArea;
              printArea.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
              pDC->DrawText("My Test is OK.", printArea, DT_NOPREFIX | DT_WORDBREAK); // This prints OK

              CScrollView::OnPrint(pDC, pInfo);
              }

              N 1 Reply Last reply
              0
              • J Joe Smith IX

                I use the ReportViewDlg to show the report in the custom control (see number 3 in my initial post). I think the pDC is correct. Here is the function where I inserted the DrawText that prints OK.

                void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
                {
                CReportDoc* pDoc = GetDocument();
                ASSERT_VALID(pDoc);
                pDoc->Draw(pDC); // This does not print anything

                CRect printArea;
                printArea.SetRect(0, 0, pDC->GetDeviceCaps(HORZRES), pDC->GetDeviceCaps(VERTRES));
                pDC->DrawText("My Test is OK.", printArea, DT_NOPREFIX | DT_WORDBREAK); // This prints OK

                CScrollView::OnPrint(pDC, pInfo);
                }

                N Offline
                N Offline
                Nelek
                wrote on last edited by
                #10

                Joe Smith IX wrote:

                CReportDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->Draw(pDC); // This does not print anything

                :doh: :doh: :confused::confused::confused: I thought you were not using Doc-View Framework.... pDoc is not the same as pDC... I think you are complicating yourself more than necessary and that you don't have your concepts clear. In the projec I downloaded there was nothing in the CTestReportView. Anyways... the second snippet prints... so what you should do is continue up from there, getting your parameters and sending them to pDC. pDoc gives no support to printing, printing is something that depends on the view. I am going to have dinner and see a film, take a look in what you are really doing, make some tests and answer me tomorrow. Maybe I won't answer till wed (depending on Football tomorrow, Spain plays in the europa's cup and I am meeting some friends to see the match with some beers :P, I know when I'm going out, but not when I'm coming back ;) :rolleyes: ) Good luck with your tests

                Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

                J 1 Reply Last reply
                0
                • J Joe Smith IX

                  Hi all, I am writing an MFC program (VC++ 6) that generates a report and supposedly able to print it out. The report is fine, but somehow it prints a blank page to the printer. After days of debugging the code, I still cannot locate the problem. This is why I can't simply post the problematic code here, I don't know which part is the problem! (Please forgive me if this is really not the right way to ask) Here I created a (much) simplified code that simulates my problem. It could be because: 1. It is SDI-based program, but I deleted the CDocument class since I don't need it. 2. I use Easy! Reports (http://www.codeproject.com/KB/miscctrl/easyreports.aspx[^]) to generate the report 3. The report is shown using a custom control (http://www.codeproject.com/KB/docview/dfv.aspx[^]) 4. Lastly, I am trying to print without using doc/view framework (http://www.codeproject.com/KB/printing/printing_wo_docview.aspx[^]) Could anyone please help me here. From what I understand, all I have to do is prepare the device context for printing (using number 4 above) and send it to the report generator function (number 2). Yet, it prints a blank page. If anyone could please take a glance and point me to the right direction, I would really appreciate it. Thanks. Download link: http://rs324.rapidshare.com/files/121245334/TestReport.zip[^]

                  B Offline
                  B Offline
                  bulg
                  wrote on last edited by
                  #11

                  Pretty cool. I dl'd and printed blank pages too! Lemme poke it with a stick...

                  B 1 Reply Last reply
                  0
                  • B bulg

                    Pretty cool. I dl'd and printed blank pages too! Lemme poke it with a stick...

                    B Offline
                    B Offline
                    bulg
                    wrote on last edited by
                    #12

                    You dn't want This[^] do you?

                    J 1 Reply Last reply
                    0
                    • B bulg

                      You dn't want This[^] do you?

                      J Offline
                      J Offline
                      Joe Smith IX
                      wrote on last edited by
                      #13

                      That one doesn't have print preview, does it? My reports should be shown on the screen to the user, along with the option to print it out. So you can't locate the problem in the code? Regards, jsix

                      1 Reply Last reply
                      0
                      • N Nelek

                        Joe Smith IX wrote:

                        CReportDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); pDoc->Draw(pDC); // This does not print anything

                        :doh: :doh: :confused::confused::confused: I thought you were not using Doc-View Framework.... pDoc is not the same as pDC... I think you are complicating yourself more than necessary and that you don't have your concepts clear. In the projec I downloaded there was nothing in the CTestReportView. Anyways... the second snippet prints... so what you should do is continue up from there, getting your parameters and sending them to pDC. pDoc gives no support to printing, printing is something that depends on the view. I am going to have dinner and see a film, take a look in what you are really doing, make some tests and answer me tomorrow. Maybe I won't answer till wed (depending on Football tomorrow, Spain plays in the europa's cup and I am meeting some friends to see the match with some beers :P, I know when I'm going out, but not when I'm coming back ;) :rolleyes: ) Good luck with your tests

                        Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

                        J Offline
                        J Offline
                        Joe Smith IX
                        wrote on last edited by
                        #14

                        I am NOT using Doc/View framework. The view/doc I am using are the classes from the custom control I am using (number 3 in my original post). The function that prints on the screen is

                        void CReportView::OnDraw(CDC* pDC)
                        {
                        CReportDoc* pDoc = GetDocument();
                        ASSERT_VALID(pDoc);
                        pDoc->Draw(pDC);
                        }

                        The pDC above is pointing to the screen, right? My thinking is that if I use the use printer's pDc, then it should print out on the printer, yes?

                        void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
                        {
                        CReportDoc* pDoc = GetDocument();
                        ASSERT_VALID(pDoc);
                        pDoc->Draw(pDC);
                        CScrollView::OnPrint(pDC, pInfo);
                        }

                        N 1 Reply Last reply
                        0
                        • J Joe Smith IX

                          I am NOT using Doc/View framework. The view/doc I am using are the classes from the custom control I am using (number 3 in my original post). The function that prints on the screen is

                          void CReportView::OnDraw(CDC* pDC)
                          {
                          CReportDoc* pDoc = GetDocument();
                          ASSERT_VALID(pDoc);
                          pDoc->Draw(pDC);
                          }

                          The pDC above is pointing to the screen, right? My thinking is that if I use the use printer's pDc, then it should print out on the printer, yes?

                          void CReportView::OnPrint(CDC* pDC, CPrintInfo* pInfo)
                          {
                          CReportDoc* pDoc = GetDocument();
                          ASSERT_VALID(pDoc);
                          pDoc->Draw(pDC);
                          CScrollView::OnPrint(pDC, pInfo);
                          }

                          N Offline
                          N Offline
                          Nelek
                          wrote on last edited by
                          #15

                          Quote from the file EasyReport.cpp /***************************************************************** * * method :void CEasyReport::Start(void) * * parameters : none * * returns : * * description: Start the report generation. Create all the fonts, etc * Try and get the printer device context, If no printer is set up as * the default printer on the system, create a screen device context. * ****************************************************************/ So you have to make that your code attach the printerDC you are getting to the m_printerDC, that printerDC is being used in the CEasyReport::CEasyReport (), in the CEasyReport::WriteParagraph (), in the CEasyReport::Start () and the CEasyReport::End (). But watch out, the definition is an HDC so maybe you can not use your CDC* directly. I suggest you to read another time carefully the articles whose code you are using, go slow through the code they provided because the support for printing is in the pre-done code you are using. You just have to find your way to correctly connect them. If I were you I would try to contact with the autors ask them directly. Good Luck :)

                          Regards. -------- M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you “The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson Rating helpfull answers is nice, but saying thanks can be even nicer.

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups