18,356
社区成员
发帖
与我相关
我的任务
分享
void CClientDlg::OnButtonsend()
{
// TODO: Add your control notification handler code here
char a[1]={'~'};
int res = pMysocket->Send(a,1);
if(res == SOCKET_ERROR)
{
CString str;
str.Format("发送数据失败,错误码:%d",WSAGetLastError());
MessageBox(str);
return;
}
Sleep(100);
int ret = pMysocket->Send(&logfont,sizeof(logfont));
if(ret == SOCKET_ERROR)
{
CString str;
str.Format("发送数据失败,错误码:%d",WSAGetLastError());
MessageBox(str);
return;
}
CString str,temp;
m_info.GetWindowText(str);
if(str.IsEmpty()|m_name.IsEmpty())
return;
temp.Format("%s说: %s",m_name,str);
pMysocket->Send(temp.GetBuffer(temp.GetLength()),temp.GetLength());
m_info.SetWindowText("");
m_info.SetFocus();
}
void CClientDlg::ReceiveData()
{
if(font)
{
LOGFONT temp;
//接收传来的字体数据
int factdata = pMysocket->Receive((LOGFONT*)&temp,sizeof(temp));
m_Font.Detach();
m_Font.CreateFontIndirect(&temp); //直接创建字体
m_RichFont.SetFont(&m_Font); //设置字体
font = FALSE;
}
else
{
char buffer[200];
//接收传来的数据
int factdata = pMysocket->Receive(buffer,200);
buffer[factdata] = 0;
if(buffer[0] == '~')
{
font = TRUE;
return;
}
else
{
CString str;
str.Format("%s",buffer);
m_RichFont.SetWindowText(str);
m_RichFont.SetSel(0,-1);
m_RichFont.Copy();
m_RichEdit.Paste();
}
}
}