Hello,
First, you need to read the text from the file. One way to do this would be to use the CFile class to open and read the file data.
CFile file;
CFileException ex;
CString fileText;
if (!file.Open(_T("Hello.txt"),
CFile::modeRead | CFile::shareDenyWrite, &ex))
{
TCHAR szError[1024];
ex.GetErrorMessage(szError, 1024);
TRACE1("Couldn't open source file: %s\n", szError);
}
else
{
UINT nBytes = (UINT)file.GetLength();
int nChars = nBytes / sizeof(TCHAR);
nBytes = file.Read(fileText.GetBuffer(nChars), nBytes);
fileText.ReleaseBuffer(nChars);
}
Then you have a few options for displaying the text.
If you are working on a dialog app the easiest thing might be to add a static control to the dialog and just set the text for the window
CWnd *pwndStatic = this->GetDlgItem(IDC_LABEL);
if (pwndStatic)
{
pwndStatic->SetWindowText(m_fileText);
}
Or, if you are trying something more sophisticated you can override the OnPaint method for the window you want the text in and draw the text yourself:
CPaintDC dc(this);
CRect rect;
GetClientRect(&rect);
dc.DrawText(m_fileText, &rect, DT_LEFT | DT_NOCLIP);
Hope this helps!