⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chatdialog.cpp

📁 一般压缩文件都没密码
💻 CPP
字号:
// ChatDialog.cpp : implementation file
//

#include "stdafx.h"
#include "MyQQClient.h"
#include "ChatDialog.h"
#include "MainSocket.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChatDialog dialog


CChatDialog::CChatDialog(CWnd* pParent /*=NULL*/)
	: CDialog(CChatDialog::IDD, pParent)
{
	//{{AFX_DATA_INIT(CChatDialog)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CChatDialog::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CChatDialog)
	DDX_Control(pDX, IDC_SENDMESSAGE, m_MessageCtrl);
	DDX_Control(pDX, IDC_RECEIVE, m_ReceiveCtrl);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CChatDialog, CDialog)
	//{{AFX_MSG_MAP(CChatDialog)
	ON_WM_CLOSE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CChatDialog message handlers

void CChatDialog::DisplayMessage(CString UserName, CString strChatMessage)
{
	CString strChat;
	int nSLine = m_ReceiveCtrl.GetLineCount();
	CHARFORMAT2 uFont;
	uFont.cbSize = sizeof(uFont);
	uFont.dwMask = CFM_COLOR;
	uFont.dwEffects = ~CFE_AUTOCOLOR;
	uFont.crTextColor = RGB(200,90,50);
	
	m_ReceiveCtrl.GetWindowText(strChat);
	int nLength = strChat.GetLength();
	m_ReceiveCtrl.SetSel(nLength,nLength);
	m_ReceiveCtrl.SetWordCharFormat(uFont);
	strChat = UserName + _T(" 说:\r\n");
	m_ReceiveCtrl.ReplaceSel(strChat);
	
	uFont.dwEffects = CFE_AUTOCOLOR;
	m_ReceiveCtrl.SetWordCharFormat(uFont);
	
	strChat = _T("    ") + strChatMessage + _T("\r\n");
	m_ReceiveCtrl.ReplaceSel(strChat);
	
	int nELine = m_ReceiveCtrl.GetLineCount();
	m_ReceiveCtrl.LineScroll(nELine - nSLine);
}

void CChatDialog::OnOK() 
{
	CString strMessage;
	m_MessageCtrl.GetWindowText(strMessage);
	if (strMessage.IsEmpty()) return;
	((CMainSocket *)m_pClientSocket)->SendMessage(m_ClientName,strMessage);
	
	CString strChat;
	int nSLine = m_ReceiveCtrl.GetLineCount();
	CHARFORMAT2 uFont;
	uFont.cbSize = sizeof(uFont);
	uFont.dwMask = CFM_COLOR;
	uFont.dwEffects = ~CFE_AUTOCOLOR;
	uFont.crTextColor = RGB(0,0,255);
	
	m_ReceiveCtrl.GetWindowText(strChat);
	int nLength = strChat.GetLength();
	m_ReceiveCtrl.SetSel(nLength,nLength);
	m_ReceiveCtrl.SetWordCharFormat(uFont);
	strChat = ((CMainSocket *)m_pClientSocket)->m_UserName + _T(" 说:    \r\n");
	m_ReceiveCtrl.ReplaceSel(strChat);
	
	uFont.dwEffects = CFE_AUTOCOLOR;
	m_ReceiveCtrl.SetWordCharFormat(uFont);
	
	strChat = _T("    ") + strMessage + _T("\r\n");
	m_ReceiveCtrl.ReplaceSel(strChat);
	
	int nELine = m_ReceiveCtrl.GetLineCount();
//	m_ReceiveCtrl.LineScroll(nELine - nSLine);
	m_MessageCtrl.SetWindowText("");
	m_MessageCtrl.SetFocus();	
//	CDialog::OnOK();

}

void CChatDialog::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	DestroyWindow();
	CDialog::OnClose();
}

BOOL CChatDialog::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	
	// TODO: Add extra initialization here
//	SetIcon(m_hIcon, TRUE);			// Set big icon
//	SetIcon(m_hIcon, FALSE);		// Set small icon
	CString strTip;
	strTip.Format("%s 说话:",m_UserName);
	SetWindowText(strTip);

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

BOOL CChatDialog::DestroyWindow() 
{
	for(int i=0;i<m_pClientSocket->m_ChatDlgs.GetSize();i++)
	{
		CChatDialog * ChatDlg = (CChatDialog *)m_pClientSocket->m_ChatDlgs.GetAt(i);
		if(ChatDlg->m_UserName == m_UserName)
		{
			m_pClientSocket->m_ChatDlgs.RemoveAt(i);
			//delete ChatDlg;
			break;
		}
	}
	
	return CDialog::DestroyWindow();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -