This topic is now archived and is closed to further replies.


Text Functions for Win32 API

Recommended Posts

XDarkChronoX    122
I was wondering if anyone knew a way to use some sort of function like cout in a Win32 Application. I know how to use TextOut, but then I would have to plot out pixel coordinates for the function everytime I want text to be outputed and this seems too cumbersome to me. So basically I want it to automatically print at the coordinates for Win32 Applications like cout did for Console Applications. Any ideas? Thx!

Share this post

Link to post
Share on other sites
dmounty    122
You need to plot the text. There is no equivalent of cout. You can output to a file by redirecting if you wish.. but thats it. If you really want a console, then make one. I made a little console once that ran in a separate thread (wrapped very little, but you can do it more if you like). You could use string streams... treat the string stream as a buffer, then use a special member to output to the console (and clear the buffer). That way you can have cout type functionality. Thats the best idea IMO as if you want you can make it reusable. I use similar techniques to that to debug quite frequently.

Share this post

Link to post
Share on other sites
GroZZleR    820
You could just write a function to simulate cout or printf. I''m just typing this right here, but you get the idea I''m sure.

void OutputText(char *szText, bool bClear = false)
static int iY;

if(bClear == true)
iY = 0;

// I don''t remember TextOut too well, add that stuff here
// Gotta get a HDC, then Build a Font, or something like that
// Use iY for your Y co-ordinate, like..
TextOut(szText, 0, iY);

// Increase To Next Line, For Next Printing.
iY += 12;


Pretty simple and doesn''t really clear the screen, but I leave that up to you if you''re so inclined.

If you''re sick of just doing all the TextOut crap, encapsulate it. Thats what encapsulation is for =)

Share this post

Link to post
Share on other sites