Visual C++ and MFC Programming 2nd Edition

(Martin Jones) #1

Visual C++ and MFC Fundamentals Chapter 10: Characteristics of a Window's Frame


void CExoView::OnDraw(CDC* pDC)
{
CHAR *StrName = "Euzhan Palcy";

pDC->TextOut(20, 22, StrName, 12);
}

If you are writing for an international audience and involve unicode in your application,
you can declare the string using the TCHAR data type:

void CExoView::OnDraw(CDC* pDC)
{
TCHAR *StrName = "Euzhan Palcy";

pDC->TextOut(20, 22, StrName, 12);
}

Alternatively, you can use _TCHAR to declare such a variable. Normally, to initialize a
null-terminated string variable for an international audience, you should use the _T, the
TEXT or the _TEXT macros. Here is an example:

void CExoView::OnDraw(CDC* pDC)
{
char *StrName = _T("Euzhan Palcy");

pDC->TextOut(20, 22, StrName, 12);
}

You can also initialize a string variable with a value that spans various lines. To do this,
when creating the string, end each line with a double-quote and start the other with
another double-quotes. Here is an example:

void CExerciseDlg::OnMsgBox()
{
// TODO: Add your control notification handler code here
char Sentence[] = "The name you entered is not in our records.\n"
"If you think there is a mistake, please contact HR.\n"
"You can also send an email to [email protected]";
MessageBox(Sentence);
}

9.1.2 The Standard string Class...................................................................


The Standard Template Library (STL) provides a class that can be used for string
manipulation. This class is called basic_string and it was type-defined as string. To use
Free download pdf