-
SDI Text
I am trying to put text on a sdi program. here is an example of what I am doing:
CClientDC cdc(this);
CString mess;
mess.format("a message here");
cdc.textout(10,10,mess);
Now here is my problem, it prints it out to the screen, but if another window covers it, the text vanishes, and also if I want to put something else there I have to print out to that spot twice once with a really long empty string and then again with what I want there. Is there a way to keep the text there when another window covers it? And is it possible to have like a Clear Document command of some sort?
Thanks for the help in advance.
-
You should print the text during the OnPaint event of your window. If you don't have it, use ClassWizard to add it.
I think you can use something like InvalidateRect to clear it all, however that might flicker a bit.
-
Since I think this is your main view, you would use OnDraw instead of OnPaint, there you already have a device context.
Also you don't have to use CString.format for simply assigning text, you can use the = operator instead (speed!!!). Format is for numbers you want to include in the string.
Example: to get "You have a score of 156" You would use:
string.format("You have a score of %i", iScore)
or something like this.