Advertisement

TextOut Troubles

Started by May 01, 2001 02:49 PM
4 comments, last by Lor 23 years, 9 months ago
Hi guys! Sorry for this newbie question I have just started to wet my feet in windows API programming stuff, and am having trouble using the TextOut() function. Basically, I want to print the content of a string variable to the windows, i.e: TextOut(hDC, 0, 0, string, 13); Where string would be something like: char string="Oggly boggly!"; I have tried using a pointer to the string when using the TextOut function, but it just prints out stuff like TB¬||@()$J JA"#2@ Just garbage. If anyone can help me at all I would be most greatful! Thanks guys, Lor.
What exactly is ''string'' ? is it a "char" array? If you can post the line where you define ''string'' and the TextOut line, we can probably figure it out.
// CHRIS
// CHRIS [win32mfc]
Advertisement
Ok, let me see. String is a character array, your right, my fault, this is how it should read:

char string[20]="Oggly!";

Then, I want to use TextOut() to print this in the window, what I want to know is how I get TextOut to print the contents of a char array. I have tried thinngs like this:

TextOut(hDC, 0, 0, string, 20);

and:

TextOut(hDC, 0, 0, string[20], 20);

and passing a pointer to the string but they don''t work. Actually, passing a pointer to the string prints out garbage.

Well, this should work:

char sz[] = "Oggly Boddly!";

TextOut(hDC, 0, 0, sz, lstrlen(sz));

If you still get garbage, make sure you don't have another array declared before it that you are "over-running" - hence over-writing your sz[] array with garbage.

// CHRIS

(ADDED)
I would avoid declaring a variable with the name "string", since "string" is a C++ keyword. Likewise, you shouldn't declare variables with names like "if", "else", "for", etc.. =)



Edited by - win32mfc on May 1, 2001 4:59:04 PM
// CHRIS [win32mfc]
Thanks win32mfc, it was my string length at the end there that messed everything up! Sorry once again, but as I said I''m just starting this stuff and we all need a little guidance now and then right? Right? Or is it just me? B)
Absolutely- If you don''t ask for help, then you''re not learning it right!

// CHRIS
// CHRIS [win32mfc]

This topic is closed to new replies.

Advertisement