📄 sessiondialog.cpp
字号:
// Copyright (C) 2006 Teamviewer GmbH. All Rights Reserved.
// Copyright (C) 2002 Ultr@VNC Team Members. All Rights Reserved.
// Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
//
// This file is part of TeamViewer.
//
// TeamViewer is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.
//
// If the source code for TeamViewer is not available from the place
// whence you received this file, check http://www.teamviewer.com
// for information on obtaining it.
// SessionDialog.cpp: implementation of the SessionDialog class.
#include "stdhdrs.h"
#include "SessionDialog.h"
#include "vncviewer.h"
#include "..\winvnc\winvnc\vncservice.h"
#include "..\winvnc\winvnc\vncClient.h"
#include "..\winvnc\winvnc\vncMenu.h"
#include "..\winvnc\winvnc\roGateway.h"
#include "..\winvnc\winvnc\localization.h"
#include "..\winvnc\winvnc\global.h"
#include "..\winvnc\winvnc\textchat.h"
#define SESSION_MRU_KEY_NAME _T("Software\\TeamViewer\\MRU")
#define NUM_MRU_ENTRIES 8
extern char sz_F1[64];
extern char sz_F2[64];
extern char sz_F4[64];
extern char sz_F8[128];
extern char sz_F9[64];
extern char sz_F10[128];
extern char sz_F11[64];
extern char sz_L46[64];
extern vncMenu* menu;
extern HINSTANCE hAppInstance;
extern bool isRemoteControl;
using namespace std;
char SessionDialog::supportExplanation[512] = "";
char SessionDialog::quickSupportTitle[128] = "";
char SessionDialog::quickSupportPassword[9] = "";
HBITMAP SessionDialog::bmpLogo;
HBITMAP SessionDialog::bmpBackground;
HBITMAP SessionDialog::bmpBackgroundLeft;
HBITMAP SessionDialog::bmpBackgroundCenter;
HBITMAP SessionDialog::bmpBackgroundRight;
HBRUSH SessionDialog::brushEditControl;
HBRUSH SessionDialog::brushQSEditControl;
ColorBrushType SessionDialog::colorBrushes;
#define CLOSE_IN_SECONDS_TIMER 1
SessionDialog* SessionDialog::sessionDialog;
SessionDialog::SessionDialog(vncServer* server)
{
m_server=server;
//m_pCC = pCC;
//m_pOpt = pOpt;
//AaronP
// m_pMRU = new MRU(SESSION_MRU_KEY_NAME);
m_pMRU = new MRU(SESSION_MRU_KEY_NAME,26);
//EndAaronP
//m_pDSMPlugin = pDSMPlugin;
m_host_dialog[0] = '\0';
m_port = 0;
m_closeInSeconds=60;
sessionDialog=this;
m_connectionRequested=false;
}
SessionDialog::~SessionDialog()
{
delete m_pMRU;
}
//CW@2004
unsigned long ResolveName(char name[])
{
struct hostent *host;
if ((host = gethostbyname(name)) == NULL)
{
return -1;
}
return *((unsigned long *) host->h_addr_list[0]);
}
// It's exceedingly unlikely, but possible, that if two modal dialogs were
// closed at the same time, the static variables used for transfer between
// window procedure and this method could overwrite each other.
void SessionDialog::DoDialog()
{
//m_Closing = false;
int dialogId;
if(isQuickSupport)
{
dialogId=IDD_SIMPLE;
}
else
{
dialogId=IDD_SESSION_DLG;
}
CreateDialogParam(hAppInstance, DIALOG_MAKEINTRESOURCE(dialogId),
NULL, (DLGPROC) SessDlgProc, (LONG) this);
}
BOOL CALLBACK SessionDialog::SessDlgProc( HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
{
// This is a static method, so we don't know which instantiation we're
// dealing with. But we can get a pseudo-this from the parameter to
// WM_INITDIALOG, which we therafter store with the window and retrieve
// as follows:
SessionDialog *_this = (SessionDialog *) GetWindowLong(hwnd, GWL_USERDATA);
SetLastError(0); // sometimes an error is set and appears in random logmessages, this is not desired
switch (uMsg) {
case WM_INITDIALOG:
{
SetWindowLong(hwnd, GWL_USERDATA, lParam);
SessionDialog *_this = (SessionDialog *) lParam;
_this->m_server->SetHwndSessionDialog(hwnd);
SetClassLong(hwnd, GCL_HICON, (LONG) LoadIcon(hAppInstance, MAKEINTRESOURCE(IDI_ROVNC)));
// NT4: no SetMenuInfo() function -> don't color menu
if(menu->m_SetMenuInfo)
{
HMENU hMenu = GetMenu(hwnd);
if(isNoSave)
{
HMENU extras = GetSubMenu(hMenu, 1);
RemoveMenu(extras, 4, MF_BYPOSITION); // Separator
RemoveMenu(extras, 3, MF_BYPOSITION); // Activate
RemoveMenu(extras, 1, MF_BYPOSITION); // Host Mode
}
MENUINFO minf;
minf.cbSize = sizeof(MENUINFO);
minf.fMask = MIM_BACKGROUND|MIM_APPLYTOSUBMENUS; // set menu background color to blue
minf.hbrBack = menuBrush;
(*menu->m_SetMenuInfo)(hMenu, &minf);
MENUITEMINFO mii;
mii.cbSize = sizeof (MENUITEMINFO);
mii.fMask = MIIM_TYPE;
mii.fType = MFT_OWNERDRAW;
mii.dwTypeData = "TeamViewer SessionDialog";
int i=0;
int j,k;
while(SetMenuItemInfo(hMenu,i,TRUE,&mii) != 0) // mark all menus and submenus as ownerdrawn
{
HMENU sub;
j = 0;
while((sub=GetSubMenu(hMenu, j)))
{
k = 0;
while(SetMenuItemInfo(sub,k,TRUE,&mii) != 0)
k++;
j++;
}
i++;
}
}
bmpBackground = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP_BACKGROUND),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
bmpBackgroundLeft = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP_BACKGROUNDLEFT),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
bmpBackgroundCenter = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP_BACKGROUNDCENTER),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
bmpBackgroundRight = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP_BACKGROUNDRIGHT),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
bmpLogo = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP_LOGO),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
brushEditControl = CreateSolidBrush(EDIT_BACKCOLOR);
brushQSEditControl = CreateSolidBrush(RGB(231,227,231));
if(_this->m_server->GetServerMode() || isRemoteControl)
{
Hide();
}
else
{
Show();
}
_this->UpdateMRU(hwnd);
if(isQuickSupport)
{
char apppath[_MAX_PATH]="";
//char appDir[_MAX_PATH]="";
char logoPath[_MAX_PATH]="";
GetModuleFileName(NULL,apppath,256);
///////////////// determine the path, see http://www.codeproject.com/cpp/csplitpath.asp
char drive[_MAX_DRIVE];
char dir[_MAX_DIR];
char fname[_MAX_FNAME];
char ext[_MAX_EXT];
_splitpath(apppath,drive,dir,fname,ext);
strcpy(logoPath,drive);
strcat(logoPath,dir);
//////////////
strcat(logoPath,"logo.bmp");
HBITMAP hBitmap=(HBITMAP)LoadImage(NULL,logoPath,IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
if(hBitmap!=NULL)
{
// Custom Logo - change background to grey
DeleteObject(bmpBackground);
bmpBackground = (HBITMAP)LoadImage(GetModuleHandle(NULL),
MAKEINTRESOURCE(IDB_BITMAP_BACKGROUND_GREY),
IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION);
BITMAP bm;
GetObject(hBitmap, sizeof(bm), &bm); // see http://groups.google.de/group/fr.comp.graphisme.programmation/browse_thread/thread/9cb2a0e900225e32/e6e2ec973287a9af?q=getbitmapdimension+loadimage&rnum=1&hl=de#e6e2ec973287a9af
SIZE logoSize={bm.bmWidth,bm.bmHeight};
RECT r;
GetClientRect(hwnd, &r);
HWND logo=GetDlgItem(hwnd,IDC_LOGO);
SendMessage(logo, STM_SETIMAGE,IMAGE_BITMAP, (LPARAM)hBitmap);
MoveWindow(logo,
(r.right-r.left-bm.bmWidth)/2, 3 + (75-bm.bmHeight)/2,
bm.bmWidth, bm.bmHeight, TRUE);
// delete logo so that it will not be displayed next time standard quicksupport is used
if(!DeleteFile(logoPath))
vnclog.Print(LL_INTERR, VNCLOG("delete custom logo"));
}
SetLastError(0); // do not log error message later
if(SessionDialog::supportExplanation[0]!='\0')
{
SetDlgItemText(hwnd,IDC_SIMPLE_EXPLANATION,SessionDialog::supportExplanation);
}
if(SessionDialog::quickSupportTitle[0]!='\0')
{
SetWindowText(hwnd,SessionDialog::quickSupportTitle);
}
// set mouse pointer to hand when over TeamViewer link
SetClassLong(GetDlgItem(hwnd, ID_TV_LINK),GCL_HCURSOR,(LONG)LoadCursor(NULL, IDC_HAND));
}
///////////
int selectedButton;
switch(menu->m_properties.GetConnectionMode())
{
case Teamwork:
case RemoteControl:
selectedButton=IDC_MODE_TEAMWORK;
break;
case Presentation:
selectedButton=IDC_MODE_PRESENTATION;
break;
case Filetransfer:
selectedButton=IDC_MODE_FILETRANSFER;
break;
default:
selectedButton=IDC_MODE_TEAMWORK;
break;
}
CheckRadioButton(hwnd, IDC_MODE_PRESENTATION, IDC_MODE_FILETRANSFER, selectedButton);
// Display Local IP
char desktopname[MAX_COMPUTERNAME_LENGTH + 1 + 256];
int desktopnamelen = MAX_COMPUTERNAME_LENGTH + 1 + 256;
GetLocalName(desktopname, desktopnamelen);
// TR@2004 - display roVNC# if available
CroGateway *roGateway = CroGateway::Instance();
if (_this->m_server->UseDynGate())
{
if(roGateway->GatewayRunning())
{
if(roGateway->NumericID() != 0)
{
//if(roGateway->Licensed())
//{
// ShowWindow(GetDlgItem(hwnd,IDC_BUTTON_UPGRADE),SW_HIDE);
//}
SetDlgItemText(hwnd, IDC_MYNAME, roGateway->ClientID());
UpdatePassword();
}
else
SetDlgItemText(hwnd, IDC_MYNAME, sz_ID_DynGate_notconnected);
// If we use the Gateway technology we have to update the clientid
// 333 is just a random timerid
SetTimer(hwnd,333,1500,(TIMERPROC)SessDlgProc);
// Set download link
// For now this is a fixed value
char *dl = "http://www.teamviewer.com/download";
SetDlgItemText(hwnd, IDC_URL_DOWNLOAD, dl);
}
else if (roGateway->GatewayInstalled())
{
// DynGate installed but not running
SetDlgItemText(hwnd, IDC_MYNAME, sz_ID_DynGate_notrunning);
// If we use the Gateway technology we have to update the clientid
// 333 is just a random timerid
SetTimer(hwnd,333,1000,(TIMERPROC)SessDlgProc);
}
else
{
// DynGate neither installed nor running
SetDlgItemText(hwnd, IDC_MYNAME, sz_ID_DynGate_notinstalled);
// Set the Timer and download DynGate
// Not very nice, should be solved better...
SetTimer(hwnd,333,10,(TIMERPROC)SessDlgProc);
}
}
else
{
DisableDynGate();
}
UpdatePassword();
_this->m_fFromOptions = false;
_this->m_fFromFile = false;
#ifdef _DEBUG
SetWindowText(hwnd,"Teamviewer DEBUG Version - do not use for production! A3");
#endif
#ifdef _VISTABUILD
SetWindowText(hwnd,"Teamviewer DEBUG Version - do not use for production! Vista Edition V0.1");
#endif
if(isNoSave && !isQuickSupport)
{
#ifdef _DEBUG
SetWindowText(hwnd, "TeamViewer Portable (DEBUG Version)");
#else
SetWindowText(hwnd, "TeamViewer Portable");
#endif
}
if(_this->m_server->GetServerMode())
{
PostMessage(hwnd,WM_HIDE_SESSION_DIALOG,0,0);
}
if(!menu->m_server->GetDisableTrayIcon() && menu->m_server->AutostartSetting()>0)
{
// We show an automatic balloon tip in toolbar
SetTimer(hwnd, TIMER_BALLOON, 60000, NULL);
}
return TRUE;
}
case WM_MEASUREITEM:
{
MeasureItem(hwnd, GetMenu(hwnd), lParam);
return TRUE;
}
case WM_DRAWITEM:
{
DrawItem(lParam);
return TRUE;
}
case WM_ERASEBKGND:
{
HDC dcSrc;
HDC dcDest = (HDC)wParam;
dcSrc = CreateCompatibleDC(dcDest);
if(!dcSrc)
break;
if(isQuickSupport)
{
RECT r;
GetClientRect(hwnd, &r);
SelectObject(dcSrc, bmpBackground);
StretchBlt(dcDest, 0, 0, r.right, r.bottom, dcSrc, 0, 350-r.bottom, 1, r.bottom, SRCCOPY);
}
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -