here it is:
OnInitDialog is where I read the CStringList from the file.
AddPlayer is where I read the CStringList
RemovePlayer is where I write the CStringList
OnRemoteClose is where I write the CStringLists to the file
Code:
BOOL CPlayersDialog::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
UpdateData(TRUE); // Read what is typed in.
if(PlayerFile.Open("C:\\playerinfo.dat",CFile::modeNoTruncate|CFile::modeReadWrite|CFile::shareExclusive,NULL))
{
CArchive ar(&PlayerFile, CArchive::load); // Load its contents into a CArchive
m_Players.Serialize(ar);
m_Text.Serialize(ar);
PlayerFile.Close();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPlayersDialog::AddPlayer(CString Player)
{
int i,j;
POSITION pos;
BOOL found=false;
for(i=0;i<10;i++)
{
if(PLAYERS[i][0] == "")
{
PLAYERS[i][0]=Player;
for(j=0;j<m_Players.GetCount();j++)
{
pos=m_Players.FindIndex(j);
if( m_Players.GetAt(pos) == Player)
{
pos=m_Text.FindIndex(j);
TEXTLINE[i][0]=m_Text.GetAt(pos);
found=true;
break;
}
}
if(!found)
{
m_Players.AddTail(Player);
m_Text.AddTail("New Player");
TEXTLINE[i][0]=("New Player");
}
break;
}
}
UpdateData(FALSE);
}
void CPlayersDialog::RemovePlayer(CString Player)
{
int i,j;
CString Name,*Text;
POSITION pos;
BOOL found=false;
UpdateData(true);
for(i=0;i<10;i++)
if(PLAYERS[i][0] == Player)
{
Name=PLAYERS[i][0];
Text= new CString(TEXTLINE[i][0]);
break;
}
for(j=0;j<m_Players.GetCount();j++)
{
pos=m_Players.FindIndex(j);
if( m_Players.GetAt(pos) == Name)
{
pos=m_Text.FindIndex(j);
m_Text.SetAt(pos,Text[0]);
found=true;
break;
}
}
if(!found)
{
m_Players.AddTail(Player);
m_Text.AddTail("New Player");
}
UpdateData(false);
delete(Text);
}
void CPlayersDialog::OnRemoteClose()
{
int i;
CFileException e;
UpdateData(true);
((CPokerpalDlg *)m_parent)->m_flag=false;
for(i=0;i<10;i++)
{
if(PLAYERS[i][0] != "")
RemovePlayer(PLAYERS[i][0]);
}
if( !PlayerFile.Open("C:\\playerinfo.dat",CFile::modeCreate|CFile::modeReadWrite|CFile::shareExclusive,&e))
afxDump << "File could not be opened " << e.m_cause << "\n";
CArchive ar (&PlayerFile, CArchive::store); // Load its contents into a CArchive
m_Players.Serialize(ar);
m_Text.Serialize(ar);
OnOK();
}