Printing text fields onto a form
-
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
-
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
Is it a matter of text alignment when using the TextOut() function? See GetTextAlign()/SetTextAlign()[^]. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
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
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.
-
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
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