资源简介
c++ tcp udp通讯 文件操作 容器操作 mysql操作 mfc界面等等 另外的服务器代码通过博客查找网页地址:http://blog.csdn.net/perfectguyipeng/article/details/71698826
代码片段和文件信息
// Chat.cpp : 实现文件
//
#include “stdafx.h“
#include “MyChattingroom_client.h“
#include “Chat.h“
#include “afxdialogex.h“
struct apple
{
char mymesssage[1024] ;
};
apple myapple ;
// CChat 对话框
IMPLEMENT_DYNAMIC(CChat CDialogEx)
CChat::CChat(CWnd* pParent /*=NULL*/)
: CDialogEx(CChat::IDD pParent)
m_recmessage(_T(““))
m_sendmsg(_T(““))
{
}
CChat::~CChat()
{
}
void CChat::DoDataExchange(CDataExchange* pDX)
{
CDialogEx::DoDataExchange(pDX);
DDX_Control(pDX IDC_recmessage m_recmsgctr);
DDX_Text(pDX IDC_recmessage m_recmessage);
DDX_Text(pDX IDC_sendmsg m_sendmsg);
}
BEGIN_MESSAGE_MAP(CChat CDialogEx)
ON_BN_CLICKED(IDC_send &CChat::OnBnClickedsend)
ON_BN_CLICKED(IDC_BUTTON2 &CChat::OnBnClickedButton2)
ON_WM_CLOSE()
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_file &CChat::OnBnClickedfile)
ON_BN_CLICKED(IDC_chatting &CChat::OnBnClickedchatting)
END_MESSAGE_MAP()
// CChat 消息处理程序
void CChat::OnBnClickedsend()
{
// TODO: 在此添加控件通知处理程序代码
CTime time;
time = CTime::GetCurrentTime(); //获取现在时间
CString strTime = time.Format(“%Y-%m-%d %H:%M:%S “);
theApp.head.type = 3;
UpdateData(true);
m_recmessage += strTime + (CString)“(“ + theApp.m_userid + (CString)“) “ + theApp.m_username + (CString)“\r\n “ + m_sendmsg + (CString)“\r\n“;
CHead Msg;
Msg.type = 3;
strcpy_s(Msg.fromID(CStringA)theApp.m_userid);
strcpy_s(Msg.nicname(CStringA)theApp.m_username);
strcpy(Msg.id(CStringA)theApp.m_userid);
strcpy(Msg.toID(CStringA)mytoid);
strcpy_s(Msg.IPtheApp.head.IP);
strcpy_s(Msg.message(CStringA)m_sendmsg);
m_sendmsg = ““;
UpdateData(false);
m_recmsgctr.LineScroll(m_recmsgctr.GetLineCount()-1);
theApp.mytcp->Send(&Msgsizeof(Msg));
//打开文件
CString mm = (CString)“10000“ ;
ofstream outfile;
char messsage[1024] ;
char repair[200];
if(mytoid == mm) //群聊记录
{
//打开文件
strcpy_s(myapple.mymesssage(CStringA)m_recmessage) ; //消息
strcpy(repair“讨论群的聊天记录.txt“);
}
else //私聊记录
{
char tempname[100];
char tempother[100] ;
strcpy_s(tempname(CStringA)theApp.m_username) ; //我的昵称
strcpy_s(myapple.mymesssage(CStringA)m_recmessage) ; //消息
strcpy_s(tempother(CStringA)theApp.m_client[(CString)Msg.toID]) ;
sprintf(repair“%s和%s的聊天记录.txt“tempnametempother);
}
outfile.open(repairios::binary | ios::app);
outfile.write((char*)&myapplesizeof(myapple));
outfile.close();
}
BOOL CChat::OnInitDialog()
{
CDialogEx::OnInitDialog();
// TODO: 在此添加额外的初始化
mycaption =(CString)“正与(“ + mytoid + (CString)“) “ + othername + (CString)“ 聊天中“;
SetWindowTextW(mycaption);//设置对话框标题
theApp.friendid = mytoid ;
theApp.friendname = theApp.m_client[mytoid] ;
CImage m_image;
CString strPath = TEXT(“D:/Pic/b.png“);
if(m_image.Load((LPCTSTR)strPath) != S_OK) //根据图片路径加载图片
{
AfxMessageBox(TEXT(“Load Error!“));
return FALSE;
}
CRect rect;//定义矩形类
int cx = m_image.GetWidth();//
评论
共有 条评论