Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,

I am trying to print a list of things on the windows form but I am not able to do it. I am using textout to print currently but it only prints one line every time.

This is what I have done under WM_PAINT
C++
case WM_PAINT:
{
   // Draw on Window

   hdc = BeginPaint(hMainWindow, &pStruct);
   GetClientRect(hMainWindow, &clientArea);

   // Output position
   TextOut(
       hdc,          // handle to DC
       nXStart,      // x-coordinate of starting position
       nYStart,      // y-coordinate of starting position
       textBuff,       // character string
       MAX_BUFF_LEN  // number of characters
    );
}

Basically I want a list of things to be printed on a new line.I am not able to do that.Everything I add to the textBuff gets printed in one horizontal line.
Posted
Updated 28-Apr-11 22:33pm
v3
Comments
Olivier Levrey 29-Apr-11 4:34am    
Edited tags for code formating.

1 solution

Use DrawText instead of TextOut.

And group all your lines in one unique string and add a new line character at the end of each line: "\n". Or "\r\n" for carriage return + new line.
 
Share this answer
 
v3
Comments
blink0 29-Apr-11 4:39am    
Thanks, but I have tried that already.

swprintf(textBuff2, 300, L"Process %d \r\n", i+1);
wcscat(textBuff, textBuff2);
Here swprintf gets the new string i.e. Process 1 and then add it to textbuff and the loops runs again.
so process 1 process 2 process 3 gets amended to textBuff and that's the character array I am printing but it prints in a single line still.

I will try with DrawText and post my experience.
blink0 29-Apr-11 4:48am    
Thanks a lot it worked. :)
For anyone wondering I just replaced the Textout definition with the following:
DrawText(hdc, textBuff, -1, &clientArea, DT_CENTER | DT_VCENTER);//where DT_CENTER | DT_VCENTER is just preference
Olivier Levrey 29-Apr-11 4:52am    
Good :)
I saw your first tried with DT_SINGLELINE. Without it, it works better of course ;)
blink0 29-Apr-11 4:53am    
I copy pasted that from an example of DrawText but then I noticed and I was like Oh Boy lol. Thanks :)
Olivier Levrey 29-Apr-11 4:54am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900