最近利用MFC设计了一个简易的聊天器。
现将设计思路表示如下:
1、新建一个基于对话框的工程。
2、设计主界面。
3、设计其它界面,并生成各自的类。
4、编写相应的代码。现将主要代码描述如下:
读取信息函数:
typedef struct FriendInfo
{
char f_name[NAME_LENGH];
int f_ip[4];
int f_port;
}FRIEND;
void MyRead(CString filename,FRIEND *friends,int &count)
{
CFile pt;
if(!pt.Open(filename,CFile::modeRead))
{
}
else
{
count=pt.GetLength()/sizeof(FRIEND);
for(int i=0;i<count;i++)
{
pt.Read(&friends[i],sizeof(FRIEND));
}
pt.Close();
}
写入信息函数:
void MyWrite(CString filename,FRIEND *friends,int count)
{
CFile pt;
if(!pt.Open(filename,CFile::modeCreate | CFile::modeWrite))
{
}
else
{
for(int i=0;i<count;i++)
{
pt.Write(&friends[i],sizeof(FRIEND));
}
pt.Close();
}
}
在BOOL CChatApp::InitInstance(