Click to See Complete Forum and Search --> : Handling lengthy text for a Dialog Box


John Hagen
April 8th, 1999, 03:56 PM
I am trying to display a lengthy piece of text in a dialog box. Here is my present code:

//***************************************************************************************
// Module: ShowStartUpMsg7()
//
// Description: Display Simulation StartUp Message 7 to the user.
//
// Inputs: None
//
// Returns: Nothing
//
//***************************************************************************************
void CStartUpMsgs::ShowStartUpMsg7()
{
char LINE_A[] = "This is test 7a of the national broadcasting system.";
char LINE_B[] = "For the next sixty seconds this station is conducting a test.";
char LINE_C[] = "This is only a test!";
char LINE_D[] = "This is test 7b of the national broadcasting system.";
char LINE_E[] = "For the next sixty seconds this station is conducting a test.";
char LINE_F[] = "I repeat, this is only a test!";

// Format the data string that will be used for the dialog box caption line.
wsprintf( user_msg, "%s %s %s %s %s %s", LINE_A, LINE_B, LINE_C, LINE_D, LINE_E, LINE_F);
lpstr_msg_to_user = (CString) user_msg;
AfxMessageBox(lpstr_msg_to_user);
}


There must be a simpler way to format the data and then display it within any dialog (AfxMessageBox() or a standard MODAL dialog. Can anyone show me how to do this easier?

Also, is there a way to have part of the text, within the dialog, a different color? If so, can you please provide an example?

Thanks!

John

LALeonard
April 8th, 1999, 04:07 PM
Why not just do this:

CString sMsg("Really long text here!");
AfxMessageBox(sMsg);

??


LA Leonard - Definitive Solutions, Inc.

John Hagen
April 8th, 1999, 05:26 PM
My problem is I don't know how long a line of hard coded text can be. What happens when I run out of line space to the right? How do I continue on the next line of code and still use the quotations? For instance, if I wanted to have the text from this paragraph displayed in a dialog box, and I wanted to hard code it, how would I do that? As you can see this text is wrapping because it is so long. My way, which I am sure there are easier ways, would have each line as a separate line (not exceeding say 90 bytes) and then use the wsprint() to put it together. How could I use one set of quotes, as you suggest, and get it into the dialog box?

Sounds confusing, but I hope it makes sense. If I wanted to hard code one line of text that comprised of 900 characters, into the AfxMessageBox, how would I do that? That is my dilema, and why I am "piecing" the lines together.

Thanks for your response(s) and help, I greatly appreciate it!

John

LALeonard
April 8th, 1999, 05:59 PM
Hmmm... this is not as difficult as you might think, for several reasons... let me explain.

First of all, always use CStrings instead of char arrays. CString will always be at least as fast, and often faster, that char arrays. That may seem counter-intuitive, but trust me on this one.

"My problem is I don't know how long a line of hard coded text can be." A CString can hold a *lot* of chars (2 billion), so we don't have to worry about having "too much" text for a CString!

"What happens when I run out of line space to the right? How do I continue on the next line of code and still use the quotations?" Easy - just do it like this:

CString s1("This is reallllllllllllly long line one. ");
s1 += "This is reallllllllllllly long line two. ";
s1 += "This is reallllllllllllly long line three. ";
AfxMessageBox(s1);

Actually, to answer your question, literals can be concantenated like this:

CString s2("Slower " "traffic " "keep " "right.");

... so I guess you could do this:

CString s3("This is reallllllllllllly long line one. "
"This is reallllllllllllly long line two. "
"This is reallllllllllllly long line three. ");
AfxMessageBox(s3);

... but personally I like the other way better (easier to read).

HTH!


LA Leonard - Definitive Solutions, Inc.

April 8th, 1999, 07:57 PM
Just use the \ at the end of the line and your quote can go on and on:

CString myMsg = " Line .........1\
Line .... 2\
............\

Line .....100";

Todd Jeffreys
April 8th, 1999, 10:21 PM
Use this. Have one string
char* text="Whatever blah blah blah\r\nNext Line"

MessageBox that, the \r\n gets translated into a line break. That way you can specify multiline messageboxes

John Hagen
April 8th, 1999, 10:38 PM
Thanks! That is exactly what I was looking for. I'll file a copy of that away in my book of knowledge. I really do appreciate the help!!!

John

Dave Lorde
April 9th, 1999, 05:35 AM
You don't need to use \ at the end of a line at all. C++ concatenates consecutive literal strings:

CString myMsg = " Line 1\n"
" Line 2\n"
" Line 3\n"
" Line n\n";

Easy or what?

Dave