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. Printing text fields onto a form

Printing text fields onto a form

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 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.
  • H Offline
    H Offline
    Henri
    wrote on last edited by
    #1

    I am trying to print (text) fields onto a form. so I need to specify to my print fumction the exact x and y coordinates. The following code shows what I tried to do. I specify the coordinates but it prints a bit off not falling into the boxes of the from. I tried accounting for printer margins and still cannot get it to properly print. What am doing wrong ? For that matter is there a better way ? Here are parts of relevant code. omap = pDC->SetMapMode (MM_TEXT); sx = pDC->GetDeviceCaps (LOGPIXELSX); // x axis pixels per inch yx = pDC->GetDeviceCaps (LOGPIXELSY); // y axis pixels per inch xmargin = pDC->GetDeviceCaps (112); // Left margin ymargin = pDC->GetDeviceCaps (113); // Top margin r_font.CreateFont (-Size, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New"); SelectFont (&r_font); // to move half inch in and half inch down xpos would be sx/2 // and yx/2 (not accounting for printing margins). If accounting // then factor in xmargin and ymargin. TextOut (xpos, ypos, str, sz); Thanks I am using Visual C++ 5.0

    M N H 3 Replies Last reply
    0
    • H Henri

      I am trying to print (text) fields onto a form. so I need to specify to my print fumction the exact x and y coordinates. The following code shows what I tried to do. I specify the coordinates but it prints a bit off not falling into the boxes of the from. I tried accounting for printer margins and still cannot get it to properly print. What am doing wrong ? For that matter is there a better way ? Here are parts of relevant code. omap = pDC->SetMapMode (MM_TEXT); sx = pDC->GetDeviceCaps (LOGPIXELSX); // x axis pixels per inch yx = pDC->GetDeviceCaps (LOGPIXELSY); // y axis pixels per inch xmargin = pDC->GetDeviceCaps (112); // Left margin ymargin = pDC->GetDeviceCaps (113); // Top margin r_font.CreateFont (-Size, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New"); SelectFont (&r_font); // to move half inch in and half inch down xpos would be sx/2 // and yx/2 (not accounting for printing margins). If accounting // then factor in xmargin and ymargin. TextOut (xpos, ypos, str, sz); Thanks I am using Visual C++ 5.0

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      Is it a matter of text alignment when using the TextOut() function? See GetTextAlign()/SetTextAlign()[^]. Mark

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      1 Reply Last reply
      0
      • H Henri

        I am trying to print (text) fields onto a form. so I need to specify to my print fumction the exact x and y coordinates. The following code shows what I tried to do. I specify the coordinates but it prints a bit off not falling into the boxes of the from. I tried accounting for printer margins and still cannot get it to properly print. What am doing wrong ? For that matter is there a better way ? Here are parts of relevant code. omap = pDC->SetMapMode (MM_TEXT); sx = pDC->GetDeviceCaps (LOGPIXELSX); // x axis pixels per inch yx = pDC->GetDeviceCaps (LOGPIXELSY); // y axis pixels per inch xmargin = pDC->GetDeviceCaps (112); // Left margin ymargin = pDC->GetDeviceCaps (113); // Top margin r_font.CreateFont (-Size, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New"); SelectFont (&r_font); // to move half inch in and half inch down xpos would be sx/2 // and yx/2 (not accounting for printing margins). If accounting // then factor in xmargin and ymargin. TextOut (xpos, ypos, str, sz); Thanks I am using Visual C++ 5.0

        N Offline
        N Offline
        Nitheesh George
        wrote on last edited by
        #3

        Hi Henri, I think the problem is with calculating the xpos and ypos.if u want to print the text inside a box u have to find the RECT of that box. Then add xpos and ypos to RECT.left and RECT.top to get the exact position. eg: Assuming RECT rect = {20,20,100,100} ; TexOut(rect.left + xpos, rect.top + ypos , str, sz); this is a guess and if this is not the thing then plz avoid this post.

        1 Reply Last reply
        0
        • H Henri

          I am trying to print (text) fields onto a form. so I need to specify to my print fumction the exact x and y coordinates. The following code shows what I tried to do. I specify the coordinates but it prints a bit off not falling into the boxes of the from. I tried accounting for printer margins and still cannot get it to properly print. What am doing wrong ? For that matter is there a better way ? Here are parts of relevant code. omap = pDC->SetMapMode (MM_TEXT); sx = pDC->GetDeviceCaps (LOGPIXELSX); // x axis pixels per inch yx = pDC->GetDeviceCaps (LOGPIXELSY); // y axis pixels per inch xmargin = pDC->GetDeviceCaps (112); // Left margin ymargin = pDC->GetDeviceCaps (113); // Top margin r_font.CreateFont (-Size, 0, 0, 0, FW_MEDIUM, FALSE, FALSE, 0, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Courier New"); SelectFont (&r_font); // to move half inch in and half inch down xpos would be sx/2 // and yx/2 (not accounting for printing margins). If accounting // then factor in xmargin and ymargin. TextOut (xpos, ypos, str, sz); Thanks I am using Visual C++ 5.0

          H Offline
          H Offline
          Henri
          wrote on last edited by
          #4

          I looked at SetTextAlign/GetTextAlign. I did pDC->SetTextAlign ((TA_LEFT | TA_TOP | TA_NOUPDATECP)); from OnBeginPrinting. Still prints off. I dont not know if I need to account for printer margins and if so how to do so. I tried with accounting and without, as follows void CMyFormView::MyOutStr (CDC *pDC, int x, int y, char *str) { int xpos, ypos, sz; if (!(sz = strlen(str))) return; //xpos = x - r_xmargin; //account for margin //xpos = x; //do not account if (xpos < 0) xpos = 0; //ypos = y - r_ymargin; //ypos = y; r_xlast = xpos; r_ylast = ypos; pDC->TextOut (xpos, ypos, str, sz); } could not print to location I specified. Any clues, suggestions would be appreciated. Thanks. Henri

          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