textchat.cpp
来自「这是一个比较复杂的远程控制工具,分为服务器与客户斋,让你了解socket编程的知」· C++ 代码 · 共 518 行 · 第 1/2 页
CPP
518 行
nLen = SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT, EM_GETTEXTLENGTHEX, (WPARAM)&lpG, 0L);
if (szMessage != NULL) //print the sender's message
{
SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT,WM_GETTEXT, TEXTMAXSIZE-1,(LONG)m_szTextBoxBuffer);
cr.cpMax = nLen; //strlen(m_szTextBoxBuffer); // Select the last caracter to make the text insertion
cr.cpMin = cr.cpMax;
SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT,EM_EXSETSEL,0,(LONG) &cr);
SetTextFormat(false, false, 0x75, "MS Sans Serif", dwColor != GREY ? BLACK : GREY);
_snprintf(m_szTextBoxBuffer, TEXTMAXSIZE-1, "%s", szMessage);
SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT,EM_REPLACESEL,FALSE,(LONG)m_szTextBoxBuffer);
}
// Scroll down the chat window
// The following seems necessary under W9x & Me if we want the Edit to scroll to bottom...
SCROLLINFO si;
ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE|SIF_PAGE;
GetScrollInfo(GetDlgItem(m_hDlg, IDC_CHATAREA_EDIT), SB_VERT, &si);
si.nPos = si.nMax - max(si.nPage - 1, 0);
SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT, WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, si.nPos), 0L); // Scroll down the ch
// This line does the bottom scrolling correctly under NT4,W2K, XP...
// SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT, WM_VSCROLL, SB_BOTTOM, 0L);
}
//
// Send local text content
//
void TextChat::SendLocalText(void)
{
if (m_pCC->m_fFileTransferRunning) return; // Don't break a running file transfer please...
// We keep it because we could use it
// for future retype functionality. (F3)
memcpy(m_szLastLocalText, m_szLocalText, strlen(m_szLocalText));
PrintMessage(m_szLocalText, m_szLocalName, BLUE);
rfbTextChatMsg tcm;
tcm.type = rfbTextChat;
tcm.length = Swap32IfLE(strlen(m_szLocalText));
m_pCC->m_socket->SendExact((char *)&tcm, sz_rfbTextChatMsg, rfbTextChat);
m_pCC->m_socket->SendExact((char *)m_szLocalText, strlen(m_szLocalText));
//and we clear the input box
SetDlgItemText(m_hDlg, IDC_INPUTAREA_EDIT, "");
return;
}
LRESULT CALLBACK TextChat::DoDialogThread(LPVOID lpParameter)
{
TextChat* _this = (TextChat*)lpParameter;
_this->m_fTextChatRunning = true;
return DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_TEXTCHAT_DLG),
NULL, (DLGPROC) TextChatDlgProc, (LONG) _this);
}
int TextChat::DoDialog()
{
m_fTextChatRunning = true; // Here.Important.
return DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_TEXTCHAT_DLG),
NULL, (DLGPROC) TextChatDlgProc, (LONG) this);
}
HWND TextChat::DisplayTextChat()
{
DWORD threadID;
HANDLE m_Thread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)(TextChat::DoDialogThread),(LPVOID)this, 0, &threadID);
ResumeThread(m_Thread);
return (HWND)0;
}
//
//
//
void TextChat::KillDialog()
{
// DestroyWindow(m_hDlg);
m_fTextChatRunning = false;
PostMessage(m_hDlg, WM_COMMAND, IDCANCEL, 0);
}
//
//
//
void TextChat::RefuseTextChat()
{
SendTextChatRequest(CHAT_CLOSE);
SendTextChatRequest(CHAT_FINISHED);
}
//
//
//
BOOL CALLBACK TextChat::TextChatDlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) {
TextChat *_this = (TextChat *) GetWindowLong(hWnd, GWL_USERDATA);
switch (uMsg)
{
case WM_INITDIALOG:
{
SetWindowLong(hWnd, GWL_USERDATA, lParam);
TextChat *_this = (TextChat *) lParam;
if (_this->m_szLocalText == NULL || _this->m_szRemoteText == NULL)
EndDialog(hWnd, FALSE);
_this->m_hWnd = hWnd;
_this->m_hDlg = hWnd;
if (_snprintf(_this->m_szRemoteName,MAXNAMESIZE-1,"%s", _this->m_pCC->GetClientName()) < 0 )
{
_this->m_szRemoteName[MAXNAMESIZE-4]='.';
_this->m_szRemoteName[MAXNAMESIZE-3]='.';
_this->m_szRemoteName[MAXNAMESIZE-2]='.';
_this->m_szRemoteName[MAXNAMESIZE-1]=0x00;
}
const long lTitleBufSize = 256;
char szTitle[lTitleBufSize];
_snprintf(szTitle,lTitleBufSize-1, sz_ID_CHAT_WITH_S_ULTRAVNC,_this->m_szRemoteName);
SetWindowText(hWnd, szTitle);
memset(_this->m_szLocalText, 0, TEXTMAXSIZE);
// Local message box
SetDlgItemText(hWnd, IDC_INPUTAREA_EDIT, _this->m_szLocalText);
// Chat area
_this->SetTextFormat(); // Set character formatting and background color
SendDlgItemMessage( hWnd, IDC_CHATAREA_EDIT, EM_SETBKGNDCOLOR, FALSE, 0xFFFFFF );
// if (!_this->m_fPersistentTexts)
{
memset(_this->m_szLastLocalText, 0, TEXTMAXSIZE); // Future retype functionnality
memset(_this->m_szTextBoxBuffer, 0, TEXTMAXSIZE); // Clear Chat area
// Load and display diclaimer message
// sf@2005 - Only if the DSMplugin is used
if (!_this->m_pCC->m_server->GetDSMPluginPointer()->IsEnabled())
{
if (LoadString(hAppInstance,IDS_WARNING,_this->m_szRemoteText, TEXTMAXSIZE -1) )
_this->PrintMessage(_this->m_szRemoteText, NULL ,GREY);
}
}
// else
// SendDlgItemMessage(hWnd,IDC_CHATAREA_EDIT, WM_SETTEXT, 0, (LONG)_this->m_szTextBoxBuffer);
// Scroll down the chat window
// The following seems necessary under W9x & Me if we want the Edit to scroll to bottom...
SCROLLINFO si;
ZeroMemory(&si, sizeof(SCROLLINFO));
si.cbSize = sizeof(SCROLLINFO);
si.fMask = SIF_RANGE|SIF_PAGE;
GetScrollInfo(GetDlgItem(hWnd, IDC_CHATAREA_EDIT), SB_VERT, &si);
si.nPos = si.nMax - max(si.nPage - 1, 0);
SendDlgItemMessage(hWnd, IDC_CHATAREA_EDIT, WM_VSCROLL, MAKELONG(SB_THUMBPOSITION, si.nPos), 0L);
// This line does the bottom scrolling correctly under NT4,W2K, XP...
// SendDlgItemMessage(m_hDlg, IDC_CHATAREA_EDIT, WM_VSCROLL, SB_BOTTOM, 0L);
// SendDlgItemMessage(hWnd, IDC_PERSISTENT_CHECK, BM_SETCHECK, _this->m_fPersistentTexts, 0);
//if (strlen(_this->m_szUserID) > 0)
// SetDlgItemText(hWnd, IDC_USERID_EDIT, _this->m_szUserID);
SetForegroundWindow(hWnd);
return TRUE;
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
/*
case IDC_PERSISTENT_CHECK:
_this->m_fPersistentTexts = (SendDlgItemMessage(hWnd, IDC_PERSISTENT_CHECK, BM_GETCHECK, 0, 0) == BST_CHECKED);
return TRUE;
*/
case IDOK:
// Client order to close TextChat
EndDialog(hWnd, FALSE);
_this->m_fTextChatRunning = false;
_this->SendTextChatRequest(CHAT_FINISHED);
return TRUE;
case IDCANCEL:
_this->SendTextChatRequest(CHAT_CLOSE); // Client must close TextChat
EndDialog(hWnd, FALSE);
_this->m_fTextChatRunning = false;
_this->SendTextChatRequest(CHAT_FINISHED);
return TRUE;
case IDC_SEND_B:
{
memset(_this->m_szLocalText,0,TEXTMAXSIZE);
UINT nRes = GetDlgItemText( hWnd, IDC_LOCALTEXT_EDIT, _this->m_szLocalText, TEXTMAXSIZE-1);
strcat(_this->m_szLocalText, "\n");
_this->SendLocalText();
SetFocus(GetDlgItem(hWnd, IDC_INPUTAREA_EDIT));
}
return TRUE;
case IDC_INPUTAREA_EDIT:
if(HIWORD(wParam) == EN_UPDATE)
{
UINT nRes = GetDlgItemText( hWnd, IDC_INPUTAREA_EDIT, _this->m_szLocalText, TEXTMAXSIZE);
if (strstr(_this->m_szLocalText, "\n") > 0 ) // Enter triggers the message transmission
{
// nRes = GetDlgItemText( hWnd, IDC_USERID_EDIT, _this->m_szUserID, 16);
_this->SendLocalText();
}
}
return TRUE;
case IDC_HIDE_B:
_this->ShowChatWindow(false);
return TRUE;
default:
return TRUE;
break;
}
break;
case WM_SYSCOMMAND:
switch (LOWORD(wParam))
{
case SC_RESTORE:
_this->ShowChatWindow(true);
//SetFocus(GetDlgItem(hWnd, IDC_INPUTAREA_EDIT));
return TRUE;
}
break;
case WM_DESTROY:
// _this->m_fTextChatRunning = false;
// _this->SendTextChatRequest(CHAT_FINISHED);
EndDialog(hWnd, FALSE);
return TRUE;
}
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?