locked
pdc->TextOut() Newline handling RRS feed

  • Question

  •  

    Hi

     

    i am using pdc->TextOut()   to print text in printer DC the problem i am facing is that when i have a  string which has a lasrge length text is not printed to DC with text rapping (i.e once text reaches the width of page it  should automatiocally  go to   next line) the code is as follows .

     

    BOOL CWSPrint:Stick out tonguerintText(CString sData)

    {

    CFont font;

    VERIFY(font.CreateFont(40, // nHeight

    12, // nWidth

    0, // nEscapement

    0, // nOrientation

    FW_BOLD, // nWeight

    FALSE, // bItalic

    FALSE, // bUnderline

    0, // cStrikeOut

    ANSI_CHARSET, // nCharSet

    OUT_DEFAULT_PRECIS, // nOutPrecision

    CLIP_DEFAULT_PRECIS, // nClipPrecision

    DEFAULT_QUALITY, // nQuality

    DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily

    sFontName)); // lpszFacename

     

    CFont* def_font = pDC->SelectObject(&font);

    pDC->SetTextAlign(TA_LEFT);

     

    pDC->TextOut(ix,iy, sData); // write the string to DC ------ How to print multilines here ?

     

    pDC->SelectObject(def_font); // Set Back to Old Font

     

    // Delete the font object.

    font.DeleteObject();

    return TRUE;

    }//end of CWSPrint:Stick out tonguerintText

    Tuesday, January 22, 2008 8:09 AM

Answers

  • HI~

    TextOut does not draw new line automatically.

    You shoud calcualte when draw text nextline , comparing a current width with a max line width.

     

    If sData has a new line character '\n', DrawText function replace '\n' to new line.

    reference MSDN.

    http://msdn2.microsoft.com/en-us/library/ms533909.aspx

     

    Good Luck~
    Tuesday, January 22, 2008 10:08 AM

All replies

  • HI~

    TextOut does not draw new line automatically.

    You shoud calcualte when draw text nextline , comparing a current width with a max line width.

     

    If sData has a new line character '\n', DrawText function replace '\n' to new line.

    reference MSDN.

    http://msdn2.microsoft.com/en-us/library/ms533909.aspx

     

    Good Luck~
    Tuesday, January 22, 2008 10:08 AM
  •  

    I am using text out since i have to change font, line spacing  etc.. for each line

     

    how i can achive same draw text effect in Texout

     

     

    or

    hw i can use DrawText for change font, line spacing  etc.. for each line

    Tuesday, January 22, 2008 1:03 PM
  •  Kishore_83 wrote:

    hw i can use DrawText for change font, line spacing  etc.. for each line


    You can do the same for DrawText, DrawText accept a HDC as first parameter, before passing hDC to DrawText, you can select font and set text align to this DC:
    Code Snippet

    ::SelectObject(hDC, /*your font*/);
    ::SetTextAlign(hDC, /*your mode*/);


    hope it helps
    rico
    Monday, January 28, 2008 4:57 AM
  • I am doing all these things but still my test is not getting wrapped i am usg DT_WORDBREAK as a flag while doing drawtext()

    Tuesday, January 29, 2008 4:42 AM