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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printing problem

Printing problem

Scheduled Pinned Locked Moved C / C++ / MFC
helpgraphicstestingbeta-testing
7 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.
  • A Offline
    A Offline
    Acetate
    wrote on last edited by
    #1

    Hi all, I'm having what I consider to be an inexplicable problem printing in my program. I've searched message boards, google, etc.. for the past week and no dice. I have two different "reports" that are displayed in the main window of my SDI app and should be printable. All of the drawing code is contained in OnDraw(), and the program draws the appropriate report based on flags set by button presses. Both reports display fine in Print Preview, but only one will actually print. When i print the other, the printer just spits out a blank page. I've replaced the drawing code in the function to simply display a rectangle in the center of the view for testing, but it still displays fine in print preview, but wont print. The report that is displayed by default is the one that prints okay, so i'm wondering if I need to re-initialize the CDC between prints or something along those lines. Thanks for reading this far, and thanks for any help you can provide.

    D C 2 Replies Last reply
    0
    • A Acetate

      Hi all, I'm having what I consider to be an inexplicable problem printing in my program. I've searched message boards, google, etc.. for the past week and no dice. I have two different "reports" that are displayed in the main window of my SDI app and should be printable. All of the drawing code is contained in OnDraw(), and the program draws the appropriate report based on flags set by button presses. Both reports display fine in Print Preview, but only one will actually print. When i print the other, the printer just spits out a blank page. I've replaced the drawing code in the function to simply display a rectangle in the center of the view for testing, but it still displays fine in print preview, but wont print. The report that is displayed by default is the one that prints okay, so i'm wondering if I need to re-initialize the CDC between prints or something along those lines. Thanks for reading this far, and thanks for any help you can provide.

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      Acetate wrote: i'm wondering if I need to re-initialize the CDC between prints... Printing the non-working report first will tell you if it's an initialization issue or not.


      "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

      A 1 Reply Last reply
      0
      • D David Crow

        Acetate wrote: i'm wondering if I need to re-initialize the CDC between prints... Printing the non-working report first will tell you if it's an initialization issue or not.


        "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

        A Offline
        A Offline
        Acetate
        wrote on last edited by
        #3

        True true. Just tried that, and sure enough, its still shooting out a blank page. Thanks for responding.

        D 1 Reply Last reply
        0
        • A Acetate

          True true. Just tried that, and sure enough, its still shooting out a blank page. Thanks for responding.

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #4

          I'm sorry I could not be of more help. A lot of times, knowing what the problem is not is just as important as knowing what the problem is. Thomas Edison said something to the effect of "I have not failed. I've just found 10,000 ways that won't work."


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          1 Reply Last reply
          0
          • A Acetate

            Hi all, I'm having what I consider to be an inexplicable problem printing in my program. I've searched message boards, google, etc.. for the past week and no dice. I have two different "reports" that are displayed in the main window of my SDI app and should be printable. All of the drawing code is contained in OnDraw(), and the program draws the appropriate report based on flags set by button presses. Both reports display fine in Print Preview, but only one will actually print. When i print the other, the printer just spits out a blank page. I've replaced the drawing code in the function to simply display a rectangle in the center of the view for testing, but it still displays fine in print preview, but wont print. The report that is displayed by default is the one that prints okay, so i'm wondering if I need to re-initialize the CDC between prints or something along those lines. Thanks for reading this far, and thanks for any help you can provide.

            C Offline
            C Offline
            CodeBrain
            wrote on last edited by
            #5

            Do you have both reports in the SDI view or do you switch between the 2 reports? Do you print both reports on 2 pages or only one? If you do something more complex the MFC classes often won't do as they should. I think that I can say that I have stressed the MFC classes to their limits with the printing in my project... :( I would try to implement the CView::OnPrint method and try to draw your content not directly to the print DC but first into a memory DIB which is compatible to the screen. Then you have to have to use StretchDIBits to "copy" the DIB to the printer. My experience is that in general it is not a good idea to do the output directly on the printer with the same drawing code which you use for your screen output. Many printers support only a subset of the GDI functions which you can use to draw on the screen. Often the output looks ugly or you won't have any ouput. Since the PrintPreviw uses a compatible screen DC to draw (the print DC is only used to do the sizing) your output may look good on print preview but not on the printer. But there are also some cases where your output sucks in print preview but looks good on the printer. If you dont't have experience with DIBs take a look at the MSDN knowledge base article "DIBs and Their Use" from Ron Gery. So I would do something like this: void CReportView::OnPrint(DCD* pDC) { // Create compatible memory DC for screen // Create compatible DIB for the screen // Select DIB into the memory DC // Call your original drawing code using the memeory DC OnDraw(&memoryDC); // Use StretchDIBits or other DIB function to copy the bitmap to printer } Since I don't know your implementation this is just a hint how I would do it. But I think drawing in a DIB may solve your problem.

            A 1 Reply Last reply
            0
            • C CodeBrain

              Do you have both reports in the SDI view or do you switch between the 2 reports? Do you print both reports on 2 pages or only one? If you do something more complex the MFC classes often won't do as they should. I think that I can say that I have stressed the MFC classes to their limits with the printing in my project... :( I would try to implement the CView::OnPrint method and try to draw your content not directly to the print DC but first into a memory DIB which is compatible to the screen. Then you have to have to use StretchDIBits to "copy" the DIB to the printer. My experience is that in general it is not a good idea to do the output directly on the printer with the same drawing code which you use for your screen output. Many printers support only a subset of the GDI functions which you can use to draw on the screen. Often the output looks ugly or you won't have any ouput. Since the PrintPreviw uses a compatible screen DC to draw (the print DC is only used to do the sizing) your output may look good on print preview but not on the printer. But there are also some cases where your output sucks in print preview but looks good on the printer. If you dont't have experience with DIBs take a look at the MSDN knowledge base article "DIBs and Their Use" from Ron Gery. So I would do something like this: void CReportView::OnPrint(DCD* pDC) { // Create compatible memory DC for screen // Create compatible DIB for the screen // Select DIB into the memory DC // Call your original drawing code using the memeory DC OnDraw(&memoryDC); // Use StretchDIBits or other DIB function to copy the bitmap to printer } Since I don't know your implementation this is just a hint how I would do it. But I think drawing in a DIB may solve your problem.

              A Offline
              A Offline
              Acetate
              wrote on last edited by
              #6

              Hey, I'm glad I'm not the only one who's encountered problems with the MFC printing classes. I appreciate the lengthy response. I switch between the 2 reports in the SDI view, and I print the reports seperately on two different pages. (They are only one page reports as well). I'll take a look at the DIB functions and get up to speed. The only thing is, I don't use any different GDI functions in the two reports, and the first one prints fine. Thanks again for taking the time to help.

              C 1 Reply Last reply
              0
              • A Acetate

                Hey, I'm glad I'm not the only one who's encountered problems with the MFC printing classes. I appreciate the lengthy response. I switch between the 2 reports in the SDI view, and I print the reports seperately on two different pages. (They are only one page reports as well). I'll take a look at the DIB functions and get up to speed. The only thing is, I don't use any different GDI functions in the two reports, and the first one prints fine. Thanks again for taking the time to help.

                C Offline
                C Offline
                CodeBrain
                wrote on last edited by
                #7

                OK, if you use the same GDI functions, than it seems to be an other problem. What are your configurations in the OnBeginPrinting and OnPrepareDC methods? Have you overwritten those methods? Do you modify the CPrintInfo object, e.g. you can set the number of pages to print.

                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