textout and \n

is there any way to use \n with textout?
LVL 5
laeuchliAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
pagladasuCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.