C++实现QQ聊天功能


C++实现QQ的聊天功能,实现了一对一聊天,群聊。实现文件的收发,以及把实现程序托盘隐藏。
资源截图
代码片段和文件信息
// ChatMoreDlg.cpp : implementation file
//

#include “stdafx.h“
#include “miniqq.h“
#include “ChatMoreDlg.h“

#include “MiniQQDlg.h“

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CChatMoreDlg dialog


CChatMoreDlg::CChatMoreDlg(CWnd* pParent /*=NULL*/)
: CDialog(CChatMoreDlg::IDD pParent)
{
//{{AFX_DATA_INIT(CChatMoreDlg)
//}}AFX_DATA_INIT
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINframe);

m_pSocketChat = NULL;

//设置 192.168.0.100 (张三) 23:23:23 的颜色 为天蓝色
ZeroMemory(&m_cfBlue sizeof(CHARFORMAT));
m_cfBlue.cbSize = sizeof(CHARFORMAT);
m_cfBlue.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
strcpy(m_cfBlue.szFaceName _T(“宋体“));//设置字体 System
m_cfBlue.crTextColor = RGB(0 128 255); //文字颜色
m_cfBlue.dwEffects = 0;
// m_cfBlue.yHeight = 12 * 12 * 2;//文字高度

//设置 聊天内容 的颜色 为黑色
ZeroMemory(&m_cfBlack sizeof(CHARFORMAT));
m_cfBlack.cbSize = sizeof(CHARFORMAT);
m_cfBlack.dwMask = CFM_BOLD | CFM_COLOR | CFM_FACE | CFM_ITALIC | CFM_SIZE | CFM_UNDERLINE;
strcpy(m_cfBlack.szFaceName _T(“宋体“));//设置字体
m_cfBlack.crTextColor = RGB(0 0 0); //文字颜色
    m_cfBlack.dwEffects = 0;
//    m_cfBlack.yHeight = 12*12 * 3;//文字高度
}


void CChatMoreDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CChatMoreDlg)
DDX_Control(pDX IDC_RICHEDIT m_richedit);
//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChatMoreDlg CDialog)
//{{AFX_MSG_MAP(CChatMoreDlg)
ON_BN_CLICKED(ID_BTN_SEND OnBtnSend)
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChatMoreDlg message handlers

void CChatMoreDlg::OnCancel() 
{
this->ShowWindow(SW_HIDE);
//CDialog::OnCancel();
}

void CChatMoreDlg::OnClose() 
{
// TODO: Add your message handler code here and/or call default
this->ShowWindow(SW_HIDE);

// CDialog::OnClose();
}

BOOL CChatMoreDlg::OnInitDialog() 
{
CDialog::OnInitDialog();

// Set the icon for this dialog.  The framework does this automatically
//  when the application‘s main window is not a dialog
SetIcon(m_hIcon TRUE); // Set big icon
SetIcon(m_hIcon FALSE); // Set small icon

// TODO: Add extra initialization here
m_pSocketChat = &(((CMiniQQDlg *)AfxGetMainWnd())->m_socketChat);

return FALSE;  // return TRUE unless you set the focus to a control
              // EXCEPTION: OCX Property Pages should return FALSE
}

void CChatMoreDlg::OnBtnSend() 
{
//1. 获取 用户输入的内容sSend
//待处理:当用户输入超过RecvProcChat中定义的1024字节时,需要分段处理
CString sSend;
GetDlgItemText(IDC_EDIT_MSG sSend);
SetDlgItemText(IDC_EDIT_MSG ““);
GetDlgItem(IDC_EDIT_MSG)->SetFocus();
if (sSend.IsEmpty()) return;

//2. SendTo()向m_pUserInfo->sIP的6001端口发送数据sSend
CHATMSG sendBuf = {CHAT_MORE 0};
strcpy

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2018-08-13 16:04  MiniQQ_Only_UDP
     文件        4774  2017-04-14 10:24  MiniQQ_Only_UDPChatMoreDlg.cpp
     文件        1540  2017-04-14 10:24  MiniQQ_Only_UDPChatMoreDlg.h
     文件       21278  2017-04-14 10:24  MiniQQ_Only_UDPChatOneDlg.cpp
     文件        2550  2017-04-14 10:24  MiniQQ_Only_UDPChatOneDlg.h
     文件        2673  2017-04-14 10:24  MiniQQ_Only_UDPCommon.cpp
     文件         690  2017-04-14 10:24  MiniQQ_Only_UDPCommon.h
     目录           0  2018-08-13 16:04  MiniQQ_Only_UDPDebug
     文件       31468  2017-11-22 17:17  MiniQQ_Only_UDPDebugCL.read.1.tlog
     文件        5072  2017-11-22 17:17  MiniQQ_Only_UDPDebugCL.write.1.tlog
     文件       40764  2017-11-22 17:17  MiniQQ_Only_UDPDebugChatMoreDlg.obj
     文件       13429  2017-11-22 17:17  MiniQQ_Only_UDPDebugChatMoreDlg.sbr
     文件       11372  2017-11-22 17:17  MiniQQ_Only_UDPDebugChatOneDlg.sbr
     文件       21872  2017-11-22 17:17  MiniQQ_Only_UDPDebugCommon.obj
     文件        2865  2017-11-22 17:17  MiniQQ_Only_UDPDebugCommon.sbr
     文件          61  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.lastbuildstate
     文件        9726  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.log
     文件       31022  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.obj
     文件    24641536  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.pch
     文件       10028  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.sbr
     文件           0  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.unsuccessfulbuild
     文件           0  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQ.write.1.tlog
     文件      127129  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQDlg.obj
     文件       31373  2017-11-22 17:17  MiniQQ_Only_UDPDebugMiniQQDlg.sbr
     文件       16044  2017-11-22 17:17  MiniQQ_Only_UDPDebugMyAsyncSocket.obj
     文件        8004  2017-11-22 17:17  MiniQQ_Only_UDPDebugMyAsyncSocket.sbr
     文件       27860  2017-11-22 17:17  MiniQQ_Only_UDPDebugNicknameDlg.obj
     文件        3467  2017-11-22 17:17  MiniQQ_Only_UDPDebugNicknameDlg.sbr
     文件       17366  2017-11-22 17:17  MiniQQ_Only_UDPDebugRecvFile.obj
     文件       11393  2017-11-22 17:17  MiniQQ_Only_UDPDebugRecvFile.sbr
     文件       17024  2017-11-22 17:17  MiniQQ_Only_UDPDebugSendFile.obj
............此处省略40个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)