📄 clientconnection.cpp
字号:
connected = true;
// Modif sf@2002 - bit of a hack...and unsafe
if (strlen( m_pApp->m_options.m_clearPassword) > 0)
strncpy(m_clearPasswd, m_pApp->m_options.m_clearPassword, MAXPWLEN);
// Connect if we're not already connected
if (m_sock == INVALID_SOCKET)
connected = Connect();
if (!connected)
{
m_port=-1;
if(m_sock != INVALID_SOCKET)
{
shutdown(m_sock, SD_BOTH);
closesocket(m_sock);
}
m_sock = INVALID_SOCKET;
return 0;
}
else
{
SetSocketOptions();
SessionDialog::SetStatus(sz_IDS_MSG_NEGOTIATING);
NegotiateProtocolVersion();
if(m_abort_connection) // User wants to abort connection
return 0;
try
{
SessionDialog::SetStatus(sz_IDS_MSG_AUTHENTICATING);
Authenticate();
}
catch(Exception &e)
{
// in TeamViewer we want to show Connection dialog again
e.Report();
connected = false;
closesocket(m_sock);
m_sock = INVALID_SOCKET;
m_port = -1;
m_encPasswd[0]='\0';
return 0;
}
if(m_abort_connection) // User wants to abort connection
return 0;
}
//}
SendClientInit();
if(m_abort_connection) // User wants to abort connection
return 0;
/*TR@2004
These lines handle the way of connection.
The user can choose the following options from the connection dialog :
rfbMC_TeamworkClient;
rfbMC_PresentationServer;
rfbMC_RemotecontrolClient;
rfbMC_TeamworkClient;
rfbMC_PresentationServer;
*/
//we are server
if (m_opts.m_ActiveMode & rfbMC_Servermodes)
{
if (m_ServerKnowsModeChange)
{
// a server mode was requested for startup - no need for the rest of the init
SendModeChangeRequest(m_opts.m_ActiveMode - rfbMC_Servermodes); // partner is the corresponding client
SwitchToServermode();
return -1;
}
else
{
// we are connected to a standard vnc client, not roVNC - fallback to regular remote control
m_opts.m_ActiveMode = rfbMC_RemotecontrolClient;
}
}
if (m_ServerKnowsModeChange)
SendModeChangeRequest(m_opts.m_ActiveMode + rfbMC_Servermodes); // partner is the corresponding server
CreateDisplay();
//CreateToolbar();
//CreateToolbarHandle();
ReadServerInit();
CreateLocalFramebuffer();
SetupPixelFormat();
Createdib();
SetFormatAndEncodings();
// Show Window
if (m_opts.m_ActiveMode == rfbMC_PresentationClient) {
//alte Einstellung
//m_opts.m_localCursor = NORMALCURSOR;
//m_opts.m_requestShapeUpdates = false; // Remote Server sends mouse shape
m_opts.ShowRemoteCursor(true);
//remote Cursor is being set by VNCOptions dialog
// Bei direktem Start im Server-Modus Fenster unterdr點ken
SizeWindow();
}
// else
// m_opts.m_requestShapeUpdates = true;
// This starts the worker thread.
// The rest of the processing continues in run_undetached.
LowLevelHook::Initialize(m_hwndMain);
ViewerAppCounter++;
start_undetached();
logConnection=true;
return 1;
}
////////////////////////////////////////////////////////
void ClientConnection::CreateButtons()
{
RECT r;
int nr_buttons;
TBBUTTON ButtonEnd = {0,ID_BUTTON_END,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonRefresh = {1,ID_BUTTON_REFRESH,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonOptions = {2,ID_BUTTON_PROPERTIES,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonChat = {3,ID_BUTTON_TEXTCHAT,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonFiletransfer = {4,ID_BUTTON_FTRANS,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonSingleWindow = {5,ID_BUTTON_SW,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonDirChange = {6,ID_BUTTON_DIRCHANGE,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonFullscreen = {7,ID_BUTTON_FULLSCREEN,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonDesktop = {11,ID_BUTTON_DESKTOP,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonEnableInput = {12,ID_BUTTON_ENABLE_INPUT,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonDisableInput = {13,ID_BUTTON_DISABLE_INPUT,TBSTATE_ENABLED,TBSTYLE_BUTTON};
TBBUTTON ButtonCAD = {14,ID_BUTTON_CAD,TBSTATE_ENABLED,TBSTYLE_BUTTON};
// remove all buttons
while(SendMessage(m_hwndTB, (UINT)TB_DELETEBUTTON, 0, 0)) ;
nr_buttons = 4;
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonEnd);
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonRefresh);
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonOptions);
if(m_fServerIsUltra)
{
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonChat);
++nr_buttons;
}
if(m_fServerKnowsFileTransfer)
{
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonFiletransfer);
++nr_buttons;
}
if(m_fServerIsUltra)
{
if(m_opts.m_DisableInput)
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonEnableInput);
else
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonDisableInput);
if(m_fHasSingleWindow)
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonDesktop);
else
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonSingleWindow);
nr_buttons += 2;
}
if(m_ServerKnowsModeChange)
{
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonDirChange);
++nr_buttons;
}
if(m_tvinfo->getPartnerInfo(tvRunningAsService) == "TRUE")
{
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonCAD);
++nr_buttons;
}
SendMessage(m_hwndTB, (UINT) TB_ADDBUTTONS, 1, (LPARAM)&ButtonFullscreen);
int width = nr_buttons * (BUTTON_WIDTH + 7);
GetClientRect(m_hwnd, &r);
HRGN rgnToolbar, rgnHandle, rgn;
rgnToolbar = CreateRoundRectRgn(0, -16, width+10, 38, 9, 9);
rgnHandle = CreateRoundRectRgn((width+10-43)/2, 0, (width+10+43)/2, 46, 6, 6);
rgn = CreateRectRgn(0,0,0,0);
CombineRgn(rgn, rgnToolbar, rgnHandle, RGN_OR);
SetWindowRgn(m_hwndTBwin, rgn, TRUE);
DeleteObject(rgnToolbar);
DeleteObject(rgnHandle);
MoveWindow(m_hwndTBwin, (r.right-r.left-width)/2-5, 0, width+10, 50, TRUE);
MoveWindow(m_hwndTB, 5, -1, width, 32, TRUE);
ShowWindow(m_hwndTB, SW_SHOW);
InvalidateRect(m_hwndTBwin, NULL, FALSE);
}
void ClientConnection::CreateToolbar()
{
WNDCLASS wndclass;
wndclass.style = 0;
wndclass.lpfnWndProc = ClientConnection::WndProcTBwin;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = m_pApp->m_instance;
wndclass.hIcon = LoadIcon(m_pApp->m_instance, MAKEINTRESOURCE(IDI_ROVNC));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
wndclass.lpszMenuName = (const TCHAR *) NULL;
wndclass.lpszClassName = VWR_WND_CLASS_NAME;
RegisterClass(&wndclass);
m_hwndTBwin = CreateWindowEx(
WS_EX_TOPMOST,
VWR_WND_CLASS_NAME,
_T("TeamViewer ToolBarWindow"),
WS_CHILD|WS_CLIPSIBLINGS,
0,
0,
0,
0,
m_hwndMain, // Parent handle
NULL, // Menu handle
m_pApp->m_instance,
NULL);
SetWindowLong(m_hwndTBwin, GWL_USERDATA, (LONG) this);
ShowWindow(m_hwndTBwin, SW_HIDE);
InitCommonControls();
m_hwndTB = CreateWindowEx(0,
TOOLBARCLASSNAME,
_T("TeamViewer ToolbarButtons"),
WS_CHILD | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NORESIZE | CCS_NOPARENTALIGN,
0, 0, 0, 0,
m_hwndTBwin,
(HMENU)IDR_TOOLBAR,
(HINSTANCE)m_pApp->m_instance,
NULL);
m_hTBImageList = ImageList_LoadImage((HINSTANCE)m_pApp->m_instance,
MAKEINTRESOURCE(IDB_BITMAP_ICONS), BUTTON_WIDTH, 1,
0, IMAGE_BITMAP, LR_CREATEDIBSECTION|LR_SHARED);
m_hTBHottrack = ImageList_LoadImage((HINSTANCE)m_pApp->m_instance,
MAKEINTRESOURCE(IDB_MOUSEOVER), BUTTON_WIDTH, 1,
0, IMAGE_BITMAP, LR_CREATEDIBSECTION|LR_SHARED);
SendMessage(m_hwndTB, (UINT) TB_SETIMAGELIST, 0, (LPARAM)m_hTBImageList);
SendMessage(m_hwndTB, (UINT) TB_SETHOTIMAGELIST, 0, (LPARAM)m_hTBHottrack);
SendMessage(m_hwndTB, (UINT) TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
// win2k: set color of hot tracking frame
COLORSCHEME scheme;
scheme.dwSize = sizeof(scheme);
scheme.clrBtnHighlight = RGB(175,175,175);
scheme.clrBtnShadow = RGB(175,175,175);
SendMessage(m_hwndTB, (UINT) TB_SETCOLORSCHEME, 0, (LPARAM)&scheme);
}
void ClientConnection::CreateDisplay()
{
// Das eigendliche HauptFenster erstellen,
// welches das VNC-Fenster und die Toolbar enth鋖t
WNDCLASS wndclass;
wndclass.style = 0;
wndclass.lpfnWndProc = ClientConnection::WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = m_pApp->m_instance;
wndclass.hIcon = LoadIcon(m_pApp->m_instance, MAKEINTRESOURCE(IDI_ROVNC));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName = (const TCHAR *) NULL;
wndclass.lpszClassName = _T("VNCMDI_Window");
RegisterClass(&wndclass);
const DWORD winstyle = WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU |
WS_MINIMIZEBOX |WS_MAXIMIZEBOX | WS_THICKFRAME | WS_VSCROLL | WS_HSCROLL | WS_CLIPSIBLINGS ;
m_hwndMain = CreateWindow(_T("VNCMDI_Window"),
_T("TeamViewer Live Presentation"),
winstyle,
CW_USEDEFAULT,
CW_USEDEFAULT,
320,200,
NULL, // Parent handle
NULL, // Menu handle
m_pApp->m_instance,
NULL);
SetWindowLong(m_hwndMain, GWL_USERDATA, (LONG) this);
RECT r;
SetRect(&r, 0, 0, 0, 0);
AdjustWindowRect(&r, winstyle, FALSE);
m_borderWidth = r.right - r.left;
m_borderHeight = r.bottom - r.top;
CreateToolbar();
memset(&wndclass, 0, sizeof(wndclass));
wndclass.style = 0;
wndclass.lpfnWndProc = ClientConnection::WndProchwnd;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = m_pApp->m_instance;
wndclass.hIcon = LoadIcon(m_pApp->m_instance, MAKEINTRESOURCE(IDI_ROVNC));
switch (m_opts.m_localCursor)
{
case NOCURSOR:
wndclass.hCursor = LoadCursor(m_pApp->m_instance, MAKEINTRESOURCE(IDC_NOCURSOR));
break;
case NORMALCURSOR:
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
break;
case DOTCURSOR:
default:
wndclass.hCursor = LoadCursor(m_pApp->m_instance, MAKEINTRESOURCE(IDC_DOTCURSOR));
}
wndclass.hbrBackground = NULL;
wndclass.lpszMenuName = (const TCHAR *) NULL;
wndclass.lpszClassName = VWR_WND_CLASS_NAME_VIEWER;
RegisterClass(&wndclass);
m_hwnd = CreateWindow(VWR_WND_CLASS_NAME_VIEWER,
_T("TeamViewer Live Presentation"),
WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE,
0,
0,
CW_USEDEFAULT, // x-size
CW_USEDEFAULT, // y-size
m_hwndMain, // Parent handle
NULL, // Menu handle
m_pApp->m_instance,
NULL);
//ShowWindow(m_hwnd, m_opts.m_ActiveMode == rfbMC_FiletransferClient ? SW_HIDE : SW_SHOW);
// record which client created this window
SetWindowLong(m_hwnd, GWL_USERDATA, (LONG) this);
// Create a memory DC which we'll use for drawing to
// the local framebuffer
m_hBitmapDC = CreateCompatibleDC(NULL);
m_hCacheBitmapDC = CreateCompatibleDC(NULL);
// Set a suitable palette up
if (GetDeviceCaps(m_hBitmapDC, RASTERCAPS) & RC_PALETTE) {
vnclog.Print(3, VNCLOG(_T("Palette-based display - %d entries, %d reserved")),
GetDeviceCaps(m_hBitmapDC, SIZEPALETTE), GetDeviceCaps(m_hBitmapDC, NUMRESERVED));
BYTE buf[sizeof(LOGPALETTE)+216*sizeof(PALETTEENTRY)];
LOGPALETTE *plp = (LOGPALETTE *) buf;
int pepos = 0;
for (int r = 5; r >= 0; r--) {
for (int g = 5; g >= 0; g--) {
for (int b = 5; b >= 0; b--) {
plp->palPalEntry[pepos].peRed = r * 255 / 5;
plp->palPalEntry[pepos].peGreen = g * 255 / 5;
plp->palPalEntry[pepos].peBlue = b * 255 / 5;
plp->palPalEntry[pepos].peFlags = NULL;
pepos++;
}
}
}
plp->palVersion = 0x300;
plp->palNumEntries = 216;
m_hPalette = CreatePalette(plp);
}
//DrawMenuBar(m_hwndMain);
TheAccelKeys.SetWindowHandle(m_opts.m_NoHotKeys ? 0 : m_hwndMain);
// Set up clipboard watching
#ifndef _WIN32_WCE
// We want to know when the clipboard changes, so
// insert ourselves in the viewer chain. But doing
// this will cause us to be notified immediately of
// the current state.
// We don't want to send that.
m_initialClipboardSeen = false;
m_hwndNextViewer = SetClipboardViewer(m_hwnd);
#endif
//Added by: Lars Werner (http://lars.werner.no)
//if(TitleBar.GetSafeHwnd()==NULL)
// TitleBar.Create(m_pApp->m_instance, m_hwndMain);
SetFocus(m_hwndMain);
}
bool ClientConnection::Connect()
{
int res;
//if (!m_opts.m_NoStatus) GTGBS_ShowConnectWindow();
int one = 1;
// Check for roGateway installation
m_roGateway = false;
bool dg = false;
if (roGateway)
{
if ( roGateway->GatewayRunning() && roGateway->isClientID(m_host) )
{
//roGateway->BeginWaitAtMaster(true);
/* Connect using the Gateway */
m_roGateway = true;
m_sock = roGateway->ConnectOverGateway(m_host);
if (m_sock == INVALID_SOCKET)
res = SOCKET_ERROR;
else
res = 0;
dg = true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -