feature(master): Add remote chat feature
This commit is contained in:
180
server/2015Remote/Chat.cpp
Normal file
180
server/2015Remote/Chat.cpp
Normal file
@@ -0,0 +1,180 @@
|
||||
// Chat.cpp : implementation file
|
||||
//
|
||||
|
||||
#include "stdafx.h"
|
||||
#include "2015Remote.h"
|
||||
#include "Chat.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#define new DEBUG_NEW
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CChat dialog
|
||||
|
||||
|
||||
CChat::CChat(CWnd* pParent, ISocketBase* pIOCPServer, ClientContext* pContext)
|
||||
: DialogBase(CChat::IDD, pParent, pIOCPServer, pContext, 0)
|
||||
{
|
||||
m_hIcon = LoadIcon(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_CHAT));
|
||||
m_iocpServer = pIOCPServer;
|
||||
m_pContext = pContext;
|
||||
m_bOnClose = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void CChat::DoDataExchange(CDataExchange* pDX)
|
||||
{
|
||||
CDialog::DoDataExchange(pDX);
|
||||
DDX_Control(pDX, IDC_EDIT_TIP, m_editTip);
|
||||
DDX_Control(pDX, IDC_EDIT_NEWMSG, m_editNewMsg);
|
||||
DDX_Control(pDX, IDC_EDIT_CHATLOG, m_editChatLog);
|
||||
}
|
||||
|
||||
|
||||
BEGIN_MESSAGE_MAP(CChat, CDialog)
|
||||
ON_BN_CLICKED(IDC_BUTTON_SEND, OnButtonSend)
|
||||
ON_BN_CLICKED(IDC_BUTTON_END, OnButtonEnd)
|
||||
ON_WM_CTLCOLOR()
|
||||
ON_WM_CLOSE()
|
||||
ON_EN_SETFOCUS(IDC_EDIT_CHATLOG, OnSetfocusEditChatLog)
|
||||
ON_EN_KILLFOCUS(IDC_EDIT_CHATLOG, OnKillfocusEditChatLog)
|
||||
ON_BN_CLICKED(IDC_LOCK, &CChat::OnBnClickedButton_LOCK)
|
||||
ON_BN_CLICKED(IDC_UNLOCK, &CChat::OnBnClickedButton_UNLOCK)
|
||||
END_MESSAGE_MAP()
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CCHAT message handlers
|
||||
|
||||
BOOL CChat::OnInitDialog()
|
||||
{
|
||||
CDialog::OnInitDialog();
|
||||
|
||||
CString str;
|
||||
str.Format(_T("Զ<EFBFBD>̽<EFBFBD≯ - %s"), m_pContext->PeerName.c_str()),
|
||||
SetWindowText(str);
|
||||
m_editTip.SetWindowText(_T("<EFBFBD><EFBFBD>ʾ: <20>Է<EFBFBD><D4B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ի<EFBFBD><D4BB><EFBFBD><EFBFBD>ڷ<EFBFBD><DAB7><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD>Żᵯ<C5BB><E1B5AF>"));
|
||||
m_editNewMsg.SetLimitText(4079);
|
||||
// TODO: Add extra initialization here
|
||||
BYTE bToken = COMMAND_NEXT_CHAT;
|
||||
m_iocpServer->Send(m_pContext, &bToken, sizeof(BYTE));
|
||||
SetIcon(m_hIcon, TRUE); // Set big icon
|
||||
SetIcon(m_hIcon, FALSE); // Set small icon
|
||||
|
||||
return TRUE; // return TRUE unless you set the focus to a control
|
||||
// EXCEPTION: OCX Property Pages should return FALSE
|
||||
}
|
||||
|
||||
void CChat::OnReceive()
|
||||
{
|
||||
}
|
||||
|
||||
void CChat::OnReceiveComplete()
|
||||
{
|
||||
m_pContext->m_DeCompressionBuffer.Write((LPBYTE)_T(""), 1);
|
||||
char* strResult = (char*)m_pContext->m_DeCompressionBuffer.GetBuffer(0);
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
char Text[5120] = { 0 };
|
||||
sprintf_s(Text, _T("%s %d/%d/%d %d:%02d:%02d\r\n %s\r\n\r\n"), _T("<EFBFBD>Է<EFBFBD>:"),
|
||||
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, strResult);
|
||||
if (m_editChatLog.GetWindowTextLength() >= 20000)
|
||||
m_editChatLog.SetWindowText(_T(""));
|
||||
m_editChatLog.SetSel(-1);
|
||||
m_editChatLog.ReplaceSel(Text);
|
||||
}
|
||||
|
||||
void CChat::OnButtonSend()
|
||||
{
|
||||
char str[4096];
|
||||
GetDlgItemText(IDC_EDIT_NEWMSG, str, sizeof(str));
|
||||
if (_tcscmp(str, _T("")) == 0) {
|
||||
m_editNewMsg.SetFocus();
|
||||
return; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϢΪ<CFA2>ղ<EFBFBD><D5B2><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
m_editTip.ShowWindow(SW_HIDE);
|
||||
m_iocpServer->Send(m_pContext, (LPBYTE)str, lstrlen(str) + sizeof(char));
|
||||
SYSTEMTIME st;
|
||||
GetLocalTime(&st);
|
||||
char Text[5120] = { 0 };
|
||||
sprintf_s(Text, _T("%s %d/%d/%d %d:%02d:%02d\r\n %s\r\n\r\n"), _T("<EFBFBD>Լ<EFBFBD>:"),
|
||||
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, str);
|
||||
if (m_editChatLog.GetWindowTextLength() >= 20000)
|
||||
m_editChatLog.SetWindowText(_T(""));
|
||||
m_editChatLog.SetSel(-1);
|
||||
m_editChatLog.ReplaceSel(Text);
|
||||
m_editNewMsg.SetWindowText(_T(""));
|
||||
m_editNewMsg.SetFocus();
|
||||
}
|
||||
|
||||
void CChat::OnButtonEnd()
|
||||
{
|
||||
SendMessage(WM_CLOSE, 0, 0);
|
||||
}
|
||||
|
||||
void CChat::OnClose()
|
||||
{
|
||||
m_ContextObject->CancelIO();
|
||||
|
||||
CDialogBase::OnClose();
|
||||
}
|
||||
|
||||
HBRUSH CChat::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
|
||||
{
|
||||
if (pWnd->GetDlgCtrlID() == IDC_EDIT_CHATLOG && nCtlColor == CTLCOLOR_STATIC) {
|
||||
COLORREF clr = RGB(0, 0, 0);
|
||||
pDC->SetTextColor(clr); // <20><><EFBFBD>ú<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>ı<EFBFBD>
|
||||
clr = RGB(255, 255, 255);
|
||||
pDC->SetBkColor(clr); // <20><><EFBFBD>ð<EFBFBD>ɫ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
||||
return CreateSolidBrush(clr); // <20><>ΪԼ<CEAA><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>ɫ<EFBFBD><C9AB>Ӧ<EFBFBD><D3A6>ˢ<EFBFBD>Ӿ<EFBFBD><D3BE><EFBFBD>
|
||||
} else if (pWnd == &m_editTip && nCtlColor == CTLCOLOR_EDIT) {
|
||||
COLORREF clr = RGB(255, 0, 0);
|
||||
pDC->SetTextColor(clr); // <20><><EFBFBD>ú<EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD>ı<EFBFBD>
|
||||
clr = RGB(220, 220, 0);
|
||||
pDC->SetBkColor(clr); // <20><><EFBFBD>û<EFBFBD>ɫ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD>
|
||||
return CreateSolidBrush(clr); // <20><>ΪԼ<CEAA><D4BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><D8B1><EFBFBD>ɫ<EFBFBD><C9AB>Ӧ<EFBFBD><D3A6>ˢ<EFBFBD>Ӿ<EFBFBD><D3BE><EFBFBD>
|
||||
} else {
|
||||
return CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
|
||||
}
|
||||
}
|
||||
|
||||
void CChat::PostNcDestroy()
|
||||
{
|
||||
if (!m_bOnClose)
|
||||
OnCancel();
|
||||
CDialog::PostNcDestroy();
|
||||
delete this;
|
||||
}
|
||||
|
||||
BOOL CChat::PreTranslateMessage(MSG* pMsg)
|
||||
{
|
||||
if (pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_ESCAPE) {
|
||||
return true;
|
||||
}
|
||||
return CDialog::PreTranslateMessage(pMsg);
|
||||
}
|
||||
|
||||
void CChat::OnSetfocusEditChatLog()
|
||||
{
|
||||
if (m_editTip.IsWindowVisible())
|
||||
m_editTip.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME);
|
||||
}
|
||||
|
||||
void CChat::OnKillfocusEditChatLog()
|
||||
{
|
||||
if (m_editTip.IsWindowVisible())
|
||||
m_editTip.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_FRAME);
|
||||
}
|
||||
|
||||
void CChat::OnBnClickedButton_LOCK()
|
||||
{
|
||||
|
||||
BYTE bToken = COMMAND_CHAT_SCREEN_LOCK;
|
||||
m_iocpServer->Send(m_pContext, &bToken, sizeof(BYTE));
|
||||
}
|
||||
|
||||
void CChat::OnBnClickedButton_UNLOCK()
|
||||
{
|
||||
BYTE bToken = COMMAND_CHAT_SCREEN_UNLOCK;
|
||||
m_iocpServer->Send(m_pContext, &bToken, sizeof(BYTE));
|
||||
}
|
||||
Reference in New Issue
Block a user