Public Group

# 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.

## 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 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));

definitions:
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 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 on other sites
Is anyone can help ?

##### 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,                    DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;                    EndPaint (hwnd, &ps) ;          return 0 ;}

1. 1
Rutin
49
2. 2
3. 3
4. 4
5. 5

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633410
• Total Posts
3011723
• ### Who's Online (See full list)

There are no registered users currently online

×