|
I want to read text file into edit boxses
e.g 10 string present in a text file. I have 10 edit boxes on dialog. how i can read that 10 string into edit box?
Thanks.
|
|
|
|
|
|
I think first you should add a button in dialog and on handle of this button write the code below
void CReadFileDlg::OnReadFile()
{
CEdit* m_EditArray[10];
CStringArray FileArray;
char cTemp[256];
ifstream fin;
fin.open( _T("C:\\FileRead.txt"), ios::in|ios::nocreate );
while( !fin.eof() )
{
fin.getline( cTemp, 256, '\n' );
CString csChartoString;
csChartoString.Format( "%s", cTemp );
if( csChartoString != "" )
{
FileArray.Add( csChartoString );
}
}
int top = 10;
int bottom = 30;
for(int i = 0; i < 10; i++)
{
m_EditArray[i] = new CEdit;
DWORD dwStyle = WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON;
m_EditArray[i]->Create(dwStyle, CRect(10,top,100,bottom), this,100+i);
m_EditArray[i]->ShowWindow(TRUE);
top += 30;
bottom += 30;
}
int nArraySize = FileArray.GetSize();
int nPos = 0;
for( int nIdx= 0; nIdx < nArraySize; ++nIdx )
{
m_EditArray[nIdx]->SetWindowText( FileArray.GetAt( nIdx ));
}
}
|
|
|
|