textout and \n

is there any way to use \n with textout?
LVL 5
laeuchliAsked:
Who is Participating?
 
pagladasuConnect With a Mentor Commented:
You can try something like this. Here is a code snippet from the OnDraw function of a view class:
void CTestView::OnDraw(CDC* pDC)
{
      TEXTMETRIC tm;
      pDC->GetTextMetrics(&tm);
      int lineheight=tm.tmHeight + tm.tmExternalLeading ;
      pDC->TextOut(10,10,"Hello");
      pDC->TextOut (10,10+lineheight,"World");
      // TODO: add draw code for native data here
}

You must add or subtract the lineheight depending on the mapping mode being used.
thanks,
pagladasu
0
 
GlennDeanCommented:
I haven't found a way.  I'm sure you've done what I've done, i.e. something like
  pDC->TextOut(0,0,"Eagles\nFleetwood Mac",strlen(...));
or
  pDC->TextOut(0,0,"ZZTop\\nMadonna",strlen(...));
only to have the first display a vertical line and the second to display a \n
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

I don't think TextOut handles it. Why can't U go for DrawText(), as

CClientDC dc(this);
CRect rect(100,100,200,200);//some rectangle
dc.DrawText("First\nSecond", rect, DT_BOTTOM);

Try it out.
VinExpert
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
GlennDeanCommented:
WOW! VinExpert - I just gave your code
a try and it worked perfect!  
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi GlennDean,

Thanks for Ur try. I knew it will work. But I am using DrawText(...) instead of TextOut(...). Ok?. (And I feel it is better under such conditions!!!)

VinExpert
0
 
GlennDeanCommented:
Hey VinExpert, but as far as I'm concerned DrawText is the way to go!  I have never got TextOut to do what he wants.  AND, on top of that, DrawText seems to be a "better version" of TextOut.  
   I'm embarrashed to admit but I have, for so long done the 'ol
   "Text out at x,y"
   "recompute x via the info in TEXTMETRIC"
   "Text out at x,y"
I will put your "technique" in my memory banks for future use.
   Thank-you very much,
             Glenn
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi Glenn,

Yes, U R right. DrawText(...) is the best way to use.
U R welcome.

VinExpert
0
 
laeuchliAuthor Commented:
ok, I do this. However after that there is a problem. It won't print. Can you tell me what I can do to get it to print? I have mfc wizard code embeded.
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

> It won't print

U want it to print on to the printer?. Then put the code in the OnDraw() as

      CRect rect(100,100,800,800);
      pDC->DrawText("ABC\nXYZ", rect, DT_BOTTOM);

Try it out.
VinExpert
0
All Courses

From novice to tech pro — start learning today.