-
March 17th, 2004, 11:18 AM
#1
Outputting CStrings to a screen ?
Hi,
I have a CString that i am outputing to a screen but the problem,
i have is that i have to create the starting position of the text
then i get some other Text that needs to go onto the same line but abit further along.
I can find the length() of the first part of the string
but given that i have the X and Y position for the first part of the string and the lengtn of that first part
can i simply just add the length to the X starting position to move it along ?
if not do i need to do some converting ?
Thank again
P
-
March 17th, 2004, 11:28 AM
#2
That would only work if you setup the logical coordinates so that the size of X/Y is the size of the widest character of whatever font you are using, and the height of 1 line, etc, so X/Y coordinates are directly related to the number of characters/number of lines, etc
-
March 17th, 2004, 11:31 AM
#3
and here was i hoping that there would be a easy way ...
Thanks russ
-
March 17th, 2004, 11:36 AM
#4
Depending on what you are doing, one solution might be to only output the string when you have a full line. Set the string to the first part of the line, and when you know what the rest of the line needs to be, append that to the string and then output the whole line at once, etc.
-
March 17th, 2004, 11:38 AM
#5
Thats what i was doing bt unfortunately
some parts of the string need to be different colours ???
so if i create the string as one long string i cannot change certain parts of its colour ?
-
March 17th, 2004, 11:46 AM
#6
I thought that was probably the case.
Another possible solution might be to use GetTextExtent() to get the length in pixels of the string, and use that info to determine the X coordinate of the end of the string. I am not sure on the details as it has been a long time since I tried anything similair.
You might also try searching the forum for GetTextExtent, etc to see if a similar question has allready been asked and answered.
-
March 17th, 2004, 11:47 AM
#7
-
March 17th, 2004, 12:13 PM
#8
Your welcome.
Here is a quick test I tried in OnPaint of a dialog using GetTextExtent() that seemed to work as you want.
Code:
CPaintDC dc(this);
COLORREF clrNewColor = RGB(192,0,0);
COLORREF clrOldColor;
CSize size;
CString strText1 = "Hello ";
CString strText2 = "World!";
int nOldBackMode = dc.GetBkMode();
dc.SetBkMode(TRANSPARENT);
dc.TextOut(0, 0, strText1);
clrOldColor = dc.SetTextColor(clrNewColor);
size = dc.GetTextExtent(strText1);
dc.TextOut(size.cx, 0, strText2);
dc.SetTextColor(clrOldColor);
dc.SetBkMode(nOldBackMode);
CDialog::OnPaint();
Last edited by RussG1; March 17th, 2004 at 12:46 PM.
-
March 18th, 2004, 06:46 AM
#9
Thanks Russ
i implemented this, this morning and it works fine ..
Have a good one
P
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|