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. Help with Printing

Help with Printing

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
6 Posts 2 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.
  • E Offline
    E Offline
    Eversman
    wrote on last edited by
    #1

    Hey all, I need a little help with printing. I have it all ready to print and it print fines, but I coded it stupidly. I hard coded the coordinates of where the text is printed, so it only prints correctly on certain printers, on others it prints all messed up. So now I am trying to change it so that it works right with all printers. This is what I have done so far. CPrintDialog dlg(FALSE); CDC dc; #if 0 if (dlg.DoModal() == IDCANCEL) return; dc.Attach(dlg.GetPrinterDC()); #else PRINTDLG prtDlg; AfxGetApp()->GetPrinterDeviceDefaults(&prtDlg); dlg.m_pd.hDevMode = prtDlg.hDevMode; dlg.m_pd.hDevNames = prtDlg.hDevNames; dc.Attach(dlg.CreatePrinterDC()); #endif dc.m_bPrinting = TRUE; CRect printArea; printArea.SetRect(printArea.left/2, printArea.top/2, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); CString str("Delayed Entry"); dc.DrawText(str, printArea, DT_NOPREFIX | DT_WORDBREAK); When I try that out it compiles fine, but when I print it it doesn't work, can anyone help me out here? Thanks

    D 1 Reply Last reply
    0
    • E Eversman

      Hey all, I need a little help with printing. I have it all ready to print and it print fines, but I coded it stupidly. I hard coded the coordinates of where the text is printed, so it only prints correctly on certain printers, on others it prints all messed up. So now I am trying to change it so that it works right with all printers. This is what I have done so far. CPrintDialog dlg(FALSE); CDC dc; #if 0 if (dlg.DoModal() == IDCANCEL) return; dc.Attach(dlg.GetPrinterDC()); #else PRINTDLG prtDlg; AfxGetApp()->GetPrinterDeviceDefaults(&prtDlg); dlg.m_pd.hDevMode = prtDlg.hDevMode; dlg.m_pd.hDevNames = prtDlg.hDevNames; dc.Attach(dlg.CreatePrinterDC()); #endif dc.m_bPrinting = TRUE; CRect printArea; printArea.SetRect(printArea.left/2, printArea.top/2, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); CString str("Delayed Entry"); dc.DrawText(str, printArea, DT_NOPREFIX | DT_WORDBREAK); When I try that out it compiles fine, but when I print it it doesn't work, can anyone help me out here? Thanks

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

      Eversman wrote: ...it doesn't work, can anyone help me out here? What doesn't work? What is the code (not) doing? What are you wanting it to do? Be a little more specific instead of just "it doesn't work" and you'll get much more help.


      "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

      E 1 Reply Last reply
      0
      • D David Crow

        Eversman wrote: ...it doesn't work, can anyone help me out here? What doesn't work? What is the code (not) doing? What are you wanting it to do? Be a little more specific instead of just "it doesn't work" and you'll get much more help.


        "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

        E Offline
        E Offline
        Eversman
        wrote on last edited by
        #3

        Well it doesn't print, it prints the old stuff that I had hard coded in, but when I change it to the new way I just showed, it doesn't print, well maybe it does but it would be off the page when it printed. I am not sure if I am using the GetDeviceCaps and that such correctly.

        D 1 Reply Last reply
        0
        • E Eversman

          Well it doesn't print, it prints the old stuff that I had hard coded in, but when I change it to the new way I just showed, it doesn't print, well maybe it does but it would be off the page when it printed. I am not sure if I am using the GetDeviceCaps and that such correctly.

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

          Eversman wrote: CRect printArea; printArea.SetRect(printArea.left/2, printArea.top/2, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); This should raise a red flag. You have a variable printArea that has not been initialized/assigned a value, yet you are trying to use its left and top members. Is that intentional?


          "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

          E 1 Reply Last reply
          0
          • D David Crow

            Eversman wrote: CRect printArea; printArea.SetRect(printArea.left/2, printArea.top/2, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); This should raise a red flag. You have a variable printArea that has not been initialized/assigned a value, yet you are trying to use its left and top members. Is that intentional?


            "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

            E Offline
            E Offline
            Eversman
            wrote on last edited by
            #5

            Well, I am using this example that I found in the printing section. This is what the tutorial has it as. CRect rect; rect.left = (JRECT.Width() - size.cx)/2; rect.right = rect.left + size.cx; rect.top = (JRECT.Height() - size.cy)/2; rect.bottom = rect.top + size.cy; JDC.DrawText(str, &rect, DT_SINGLELINE); so I kinda modified it to fit what I already had. No where in the example that I see is that stuff initialized. But I need to initialize it to the printer page resolution right? So would I have to initialize it to HORZRES and VERTRES?

            D 1 Reply Last reply
            0
            • E Eversman

              Well, I am using this example that I found in the printing section. This is what the tutorial has it as. CRect rect; rect.left = (JRECT.Width() - size.cx)/2; rect.right = rect.left + size.cx; rect.top = (JRECT.Height() - size.cy)/2; rect.bottom = rect.top + size.cy; JDC.DrawText(str, &rect, DT_SINGLELINE); so I kinda modified it to fit what I already had. No where in the example that I see is that stuff initialized. But I need to initialize it to the printer page resolution right? So would I have to initialize it to HORZRES and VERTRES?

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

              Eversman wrote: No where in the example that I see is that stuff initialized. You're kidding, right? Two-thirds of the lines you've shown are initializing variables. When DrawText() is called, rect has all the right numbers.


              "When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen

              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