I could found functions that solve the problem, to open a file on a Edit control, but there is some problem with the kind of variables, first I made a cast of the name the archive, it solve but it did't with CStringArray line; to LPCTSTR
I tried:
AppendLineToMultilineEditCtrl(m_Edit,LPCTSTR(line::GetData()));
It gave the error:
Error 1 error C2510: 'line' : left of '::' must be a class/struct/union c:\Users\henitz\Documents\Visual Studio 2005\Projects\CodeDecodeCPlus2\CodeDecodeCPlus2\CodeDecodeCPlus2Dlg.cpp 108
Error 2 error C3861: 'GetData': identifier not found c:\Users\henitz\Documents\Visual Studio 2005\Projects\CodeDecodeCPlus2\CodeDecodeCPlus2\CodeDecodeCPlus2Dlg.cpp 108
Thanks
void CCodeDecodeCPlus2Dlg::OnBnClickedCode()
{
// TODO: Add your control notification handler code here
if (m_Code)
{
CStringArray line;
ReadTextFile(LPCTSTR("Teste2.txt"),line);
AppendLineToMultilineEditCtrl(m_Edit,line);
}
}
void AppendTextToEditCtrl(CEdit& edit, LPCTSTR pszText)
{
// get the initial text length
int nLength = edit.GetWindowTextLength();
// put the selection at the end of text
edit.SetSel(nLength, nLength);
// replace the selection
edit.ReplaceSel(pszText);
}
void AppendLineToMultilineEditCtrl(CEdit& edit, LPCTSTR pszText)
{
CString strLine;
// add CR/LF to text
strLine.Format(_T("\r\n%s"), pszText);
AppendTextToEditCtrl(edit, strLine);
}
void ReadTextFile(LPCTSTR pszFileName, CStringArray& arrLines)
{
arrLines.RemoveAll();
CString strLine;
TRY
{
CStdioFile file(pszFileName, CFile::modeRead);
while(file.ReadString(strLine))
arrLines.Add(strLine);
}
CATCH_ALL(e)
{
e->ReportError(); // shows what's going wrong
}
END_CATCH_ALL
}