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

📄 showmessage.cpp

📁 qq聊天的一些基本功能,要的太飞 飞师大~
💻 CPP
字号:
// ShowMessage.cpp : implementation file
//

#include "stdafx.h"
#include "ChatClient.h"
#include "ShowMessage.h"
#include "MainFrm.h"
#include "MyTreeView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CShowMessage dialog


CShowMessage::CShowMessage(CString strMessage,CString strClientName,int iTimerId,CWnd* pParent /*=NULL*/)
	: CDialog(CShowMessage::IDD, pParent)
{
	//{{AFX_DATA_INIT(CShowMessage)
	m_strMessage = _T(strMessage);
	m_strClientName = _T(strClientName);
	//}}AFX_DATA_INIT
	iID = iTimerId;
}


void CShowMessage::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CShowMessage)
	DDX_Text(pDX, IDC_MESSAGE, m_strMessage);
	DDX_Text(pDX, IDC_CLIENTNAME, m_strClientName);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CShowMessage, CDialog)
	//{{AFX_MSG_MAP(CShowMessage)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CShowMessage message handlers

BOOL CShowMessage::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	GetDlgItem(IDC_MESSAGE) ->SetFocus();
	CenterWindow(GetDesktopWindow());
	return FALSE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
extern CChatClientApp theApp;
void CShowMessage::OnOK() 
{
	// TODO: Add extra validation here
	//得到当前按钮的文本
	CString strButtonTitle;
	GetDlgItemText(IDOK,strButtonTitle);
	//杀死接受用户信息时启动的OnTimer
	CMainFrame * pFrame;
	pFrame = (CMainFrame *)AfxGetMainWnd();
	ASSERT(pFrame != NULL);
	ASSERT_VALID(pFrame);
	CMyTreeView * pView;
	pView = (CMyTreeView * )pFrame ->GetTreeView();
	pView ->KillTimer(iID);
	//恢复任务栏图标
	theApp.TaskIcon.hIcon = theApp.LoadIcon(IDI_TASKICON);
	Shell_NotifyIcon(NIM_MODIFY,&theApp.TaskIcon);	
	//删除接受用户输入时创建的新的链表项
	pView->DeleteOneClient(m_strClientName,iID);
	if(strButtonTitle == "回复")
	{
		
		m_strMessage = "";
		UpdateData(FALSE);
		SetDlgItemText(IDOK,"发送");
		GetDlgItem(IDC_MESSAGE)->SetFocus();
	}
	else
	{
		//回复发送人
		UpdateData();
		if(m_strMessage.GetLength())
		{
			//填充Message结构
			Message msObj;
			memset(&msObj,0,sizeof(Message));
			msObj.iType = USERSESSION;
			msObj.iSubType = SAYINPRIVATE;
			CString strTemp  = theApp.m_skMainSocket.GetRoomName();
			int iLen = strTemp.GetLength();
			lstrcpy(msObj.strRoom,_T(strTemp.GetBuffer(iLen)));
			strTemp.ReleaseBuffer();
			strTemp = m_strMessage;
			iLen = strTemp.GetLength();
			iLen > 1024 ? 1024 : iLen;
			lstrcpy(msObj.strContent,_T(strTemp.GetBuffer(iLen)));
			strTemp.ReleaseBuffer();
			theApp.m_skMainSocket.Send(&msObj,sizeof(Message));
			//自己的名字
			strTemp = theApp.m_skMainSocket.GetUserName();
			iLen = strTemp.GetLength();
			iLen > 20 ? 20:iLen;
			lstrcpy(msObj.strName,_T(strTemp.GetBuffer(iLen)));
			strTemp.ReleaseBuffer();
			//说话对象的名字
			
			strTemp =m_strClientName;
			iLen = strTemp.GetLength();
			iLen > 20 ? 20 : iLen;
			lstrcpy(msObj.strClientName,_T(strTemp.GetBuffer(iLen)));
			strTemp.ReleaseBuffer();
			//发送数据
			theApp.m_skMainSocket.Send(&msObj,sizeof(Message));
			
		}
		CDialog::OnOK();
	}
	
}

void CShowMessage::OnCancel() 
{
	// TODO: Add extra cleanup here
	theApp.m_skMainSocket.SetbMessage(FALSE);
	//杀死接受用户信息时启动的OnTimer
	
	CMainFrame * pFrame;
	pFrame = (CMainFrame *)AfxGetMainWnd();
	ASSERT(pFrame != NULL);
	ASSERT_VALID(pFrame);
	CMyTreeView * pView;
	pView = (CMyTreeView * )pFrame ->GetTreeView();
	pView ->KillTimer(iID);
	pView->DeleteOneClient(m_strClientName,iID);
	//恢复任务栏图标
	theApp.TaskIcon.hIcon = theApp.LoadIcon(IDI_TASKICON);
	Shell_NotifyIcon(NIM_MODIFY,&theApp.TaskIcon);


	CDialog::OnCancel();
}

⌨️ 快捷键说明

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