Jump to content
  • Advertisement
Sign in to follow this  

Text Problem (Im newbie)

This topic is 4709 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm absolutely newbie on windows programing (I started it a month ago) but I know C++ console programing from a year. On the console it was easy to write simple text with a lot of functions (iostream, fstream, filebuf, streambuf, stdio). Creating a window requires so much information (title, style, etc.) and everything is perfectly explained in MSDN but I found only one function for text (TextOut). I want to make SingleDocTemplate to show text from a file and I cannot find a way to write File Contents (they are in std::string variable) from the buffer to the SingleDocTemplate Window. Please, Can you tell me the way to show some text on a SingleDocTemplate or on any type of window (exclude console window)???

Share this post

Link to post
Share on other sites
hm...well..im not sure if this answers your question but to write text to a window i use sprintf and TextOut. for example:

char buffer[64];
int textOutput;

textOutput = sprintf( buffer,"Lives: %d", lives);
TextOut(backHDC, 10, 20, buffer, strlen(buffer));
textOutput = sprintf(buffer, "Score: %d", score);
TextOut(backHDC, 630, 20, buffer, strlen(buffer));

sprintf(char array to store data to, string literal to store, variable with string literal, like printf);

TextOut(hdc, xcoord, ycoord, where to take data from, amount to write (can be a number, but doing it this way means it takes the actual strings length..which is tidier).

i hope my rather inelegant explenation helps you in some way.

Share this post

Link to post
Share on other sites
Yeah I do it in the same way when I saw that every redraw of the window (minimize/maximize/hide behind other windows and the show it again) makes all DC drawing including text disappear. I'm not sure that TextOut is the proper way to writing a text. May be for Dialogs can use Static control.
I created Window with CEditView (Using MFC) and in that way I can write some text and set different modes with CRichEditFormat class. I don't know how to extract value of string/char* variable to DocTemplate. That I was asking about and also is the way can be used to extract text to window created with Win32 or is there similar way ?
Is anyone can help ?

Sorry for my bad English :)

[Edited by - Illuminate on December 29, 2005 2:05:20 PM]

Share this post

Link to post
Share on other sites
It has been some while but for text drawing, it would be better if you had the drawing functions inside the WM_PAINT. This way, every time the window is redrawn, the desired functions would be called.

Something like the following:

case WM_PAINT:
hdc = BeginPaint (hwnd, &ps) ;

GetClientRect (hwnd, &rect) ;

DrawText (hdc, TEXT ("Hello World!"), -1, &rect,

EndPaint (hwnd, &ps) ;
return 0 ;

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!