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

📄 session.cpp

📁 本代码是基于LINUX系统下的
💻 CPP
字号:
// Session.cpp : implementation file
//

#include "stdafx.h"
#include "Client.h"
#include "Session.h"
#include "ClientEngine.h"

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

/////////////////////////////////////////////////////////////////////////////
// CSession dialog


CSession::CSession(CWnd* pParent /*=NULL*/)
	: CDialog(CSession::IDD, pParent)
{
	//{{AFX_DATA_INIT(CSession)
	m_session_write = _T("");
	m_session_read = _T("");
	//}}AFX_DATA_INIT
}


void CSession::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CSession)
	DDX_Control(pDX, IDC_SESSION_COMBO, m_meeting_comboBox);
	DDX_Control(pDX, IDC_MEETING_LIST, m_meeting_list);
	DDX_Text(pDX, IDC_SESSION_WRITE, m_session_write);
	DDX_Text(pDX, IDC_SESSION_READ, m_session_read);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSession, CDialog)
	//{{AFX_MSG_MAP(CSession)
	ON_CBN_SELCHANGE(IDC_SESSION_COMBO, OnSelchangeSessionCombo)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_SESSION_SEND, OnSessionSend)
	ON_BN_CLICKED(IDC_SESSION_CANCEL, OnSessionCancel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSession message handlers

BOOL CSession::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_sessionId = 0;
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CSession::PostNcDestroy() 
{
	// TODO: Add your specialized code here and/or call the base class
	delete this;
	CDialog::PostNcDestroy();
}

void CSession::OnSelchangeSessionCombo() 
{
	int select = m_meeting_comboBox.GetCurSel();
	CUser* user = (CUser*)(m_meeting_comboBox.GetItemData(select));

	for(int i=0; i<m_contactors.GetSize(); i++)
	{
		if(m_contactors[i].getIDFormatOfInt() == user->getIDFormatOfInt())
		{
			AfxMessageBox(user->name + " already in meeting.");
			return;
		}
	}

	CClientEngine* engine = CClientEngine::getInstance();
	engine->addToMeeting(m_sessionId, user);
}

int CSession::getSessionID() const
{
	return m_sessionId;
}

void CSession::OnClose() 
{
	CClientEngine* engine = CClientEngine::getInstance();
	engine->closeSession(m_sessionId);
	CDialog::OnClose();
}

void CSession::OnSessionSend() 
{
	// TODO: Add your control notification handler code here
	UpdateData();

	m_session_write.TrimLeft();
	m_session_write.TrimRight();

	CClientEngine* engine = CClientEngine::getInstance();
//	
	if(!m_session_write.IsEmpty())
	{
		engine->sendSessionMessage(m_sessionId, m_session_write); 

		m_session_write = "";
		UpdateData(FALSE);

		CEdit *pEdit;
		pEdit=(CEdit *)GetDlgItem(IDC_SESSION_READ);
		int i=pEdit->GetLineCount();
		pEdit->LineScroll(i,0);

		CWnd *pEditSend=GetDlgItem(IDC_SESSION_WRITE);
		pEditSend->SetFocus();
	}
	
}

void CSession::readMessage(CString msg)
{
	m_session_read = m_session_read + "\r\n" + msg;
//	UpdateData(FALSE);
	CEdit *pEdit;
	pEdit=(CEdit *)GetDlgItem(IDC_SESSION_READ);

	pEdit->SetWindowText(m_session_read);
	int i=pEdit->GetLineCount();
	pEdit->LineScroll(i,0);
}

void CSession::OnSessionCancel() 
{
	// TODO: Add your control notification handler code here
	CDialog::OnCancel();
	
}

⌨️ 快捷键说明

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