📄 textchat.cpp
字号:
// 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;
LRESULT res = DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_TEXTCHAT_DLG),
NULL, (DLGPROC) TextChatDlgProc, (LONG) _this);
_this->m_Thread = NULL;
return res;
}
HWND TextChat::DisplayTextChat()
{
DWORD threadID;
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);
}
ChatAreaType TextChat::InstallChatArea(HWND hWnd)
{
//IDC_CHATAREA_EDIT_PLACEHOLDER
HWND placeholderRectWnd = GetDlgItem(hWnd,IDC_CHATAREA_EDIT_PLACEHOLDER);//IDC_CHATAREA_EDIT_PLACEHOLDER);
DWORD style = WS_CHILD |WS_VISIBLE | WS_BORDER
/*| TCS_HOTTRACK | TCS_RAGGEDRIGHT | TCS_MULTISELECT */
| WS_VSCROLL | WS_TABSTOP
| ES_LEFT /*| ES_SAVESEL */| ES_MULTILINE | ES_AUTOVSCROLL | ES_NOHIDESEL
| ES_READONLY | ES_WANTRETURN ;
DWORD exStyle = WS_EX_STATICEDGE;
RECT rect;
GetWindowRect(placeholderRectWnd, &rect);
POINT p;
p.x = rect.left;
p.y = rect.top;
ScreenToClient(hWnd,&p);
GetClientRect(placeholderRectWnd, &rect);
rect.left = p.x;
rect.top = p.y;
ChatAreaType result = cat_none;
result = cat_none;
HWND hwndRich = NULL;
if (hwndRich == NULL)
{
int err = GetLastError();
hwndRich = CreateWindowExA(exStyle, RICHEDIT_CLASSA, "", style,
rect.left, rect.top, rect.right, rect.bottom,
hWnd, (HMENU)IDC_CHATAREA_EDIT, (HINSTANCE)
GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
result = cat_rich2;
}
result = cat_edit;
if (hwndRich == NULL)
{
int err = GetLastError();
hwndRich = CreateWindowExA(exStyle, "EDIT", "", style , rect.left,
rect.top, rect.right - rect.left, rect.bottom -
rect.top, hWnd, (HMENU)IDC_CHATAREA_EDIT, (HINSTANCE)
GetWindowLong(hWnd, GWL_HINSTANCE), NULL);
}
if (hwndRich == NULL)
{
int err = GetLastError();
return cat_none;
}
ShowWindow(hwndRich,SW_SHOW);
return result;
}
//
//
//
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);
return TRUE;
}
_this->m_hWnd = hWnd;
_this->m_hDlg = hWnd;
string rname = _this->m_pCC->m_thread->m_tvinfo->getPartnerInfo(tvIdentity);
if(rname == "")
{
rname = _this->m_pCC->m_thread->m_tvinfo->getPartnerInfo(tvID);
if(rname == "")
rname = _this->m_pCC->GetClientName();
}
if (_snprintf(_this->m_szRemoteName,MAXNAMESIZE-1,"%s", rname.c_str()) < 0 )
{
_this->m_szRemoteName[MAXNAMESIZE-4]='.';
_this->m_szRemoteName[MAXNAMESIZE-3]='.';
_this->m_szRemoteName[MAXNAMESIZE-2]='.';
_this->m_szRemoteName[MAXNAMESIZE-1]=0x00;
}
_this->m_RichEditType = TextChat::InstallChatArea(hWnd);
const long lTitleBufSize = 256;
char szTitle[lTitleBufSize];
_snprintf(szTitle,lTitleBufSize-1, sz_ID_CHAT_WITH_S_ULTRAVNC,_this->m_pCC->GetRemoteIdentity().c_str());
//_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
}
// 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);
// Staudenmeyer@2005
UINT nRes = GetDlgItemText( hWnd, IDC_INPUTAREA_EDIT, _this->m_szLocalText, TEXTMAXSIZE-1);
//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:
{
HWND rich = GetDlgItem(hWnd,IDC_CHATAREA_EDIT);
if (rich)
DestroyWindow(rich);
// _this->SendTextChatRequest(CHAT_FINISHED);
_this->m_fTextChatRunning = false;
EndDialog(hWnd, FALSE);
return TRUE;
}
case WM_ERASEBKGND:
if (_this == NULL)
return FALSE;
return EraseBkgnd(_this->m_hDlg, wParam);
case WM_CTLCOLORBTN:
if (_this == NULL)
return FALSE;
return CtlColorBtn(wParam);
case WM_CTLCOLORSTATIC:
if (_this == NULL)
return FALSE;
return CtlColorStatic(_this->m_hDlg, wParam, lParam);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -