📄 sessiondialog.cpp
字号:
GetClientRect(hwnd,&winRect);
//get our DPI number
double yDPI = winRect.bottom / 354.0;// 354.0 is original Session Dialog Width
GetWindowRect(hwnd, &outer);
GetWindowRect((HWND)lParam, &inner);
// calculate y-pos of label
int hpos = (int)((inner.bottom+inner.top)/2/yDPI - outer.top
- GetSystemMetrics(SM_CYMENU) - GetSystemMetrics(SM_CYCAPTION));
if (hpos < 120)
col = RGB(248,248,248);
else
{
// get color from background bitmap
HDC dcSrc;
HGDIOBJ old;
dcSrc = CreateCompatibleDC(hdc);
if(dcSrc)
{
old = SelectObject(dcSrc, bmpBackground);
col = GetPixel(dcSrc, 0, hpos);
SelectObject(dcSrc, old);
DeleteDC(dcSrc);
}
}
SetBkMode(hdc, OPAQUE);
SetBkColor(hdc, col);
brush = colorBrushes[col];
if(!brush)
{
brush = CreateSolidBrush(col);
colorBrushes[col] = brush;
}
return (BOOL)brush;
}
}
}
}
return 0;
}
void SessionDialog::InvitePartner()
{
char jviewer[128]="";
ZeroMemory(&jviewer,sizeof(jviewer));
CroGateway *roGateway = CroGateway::Instance();
if(roGateway->NumericID()==0) // print an error message if DynGate is not used
{
MessageBox(NULL, sz_IDS_INVITE_FAILED_NODYNGATE, " TeamViewer Info",
MB_OK| MB_ICONEXCLAMATION | MB_SETFOREGROUND | MB_TOPMOST);
return;
}
_snprintf(jviewer, 127, "http://%s%s%d", roGateway->Gatewayname(),TV_URL_JAVA,roGateway->NumericID());
jviewer[127] = '\0';
char placeholder[9]="$$link$$";
//hier noch
std::string strMail;
if (CroGateway::Instance()->Licensed())
strMail= sz_IDS_INVITE;
else
strMail = sz_IDS_INVITE_FREE;
int iLen = menu->m_properties.CustomInvitation_Text().length();
if (iLen > 0)
{
strMail = "mailto:?subject=";
strMail += menu->m_properties.CustomInvitation_Subject();
strMail += "&body=";
strMail += menu->m_properties.CustomInvitation_Text();
}
int iPos = strMail.find(placeholder);
if (iPos >= 0)
{
int iLen = sizeof(placeholder)-1;
strMail.replace(iPos,iLen,jviewer);
}
vnclog.Print(LL_INTERR, strMail.c_str());
ShellExecute(NULL,"open",strMail.c_str(),NULL,NULL,NULL);
}
void SessionDialog::Minimize()
{
CheckForActiveConnections();
PostMessage(Hwnd(), WM_SYSCOMMAND, SC_MINIMIZE, 0);
}
void SessionDialog::Restore()
{
if (!menu)
return;
if (!menu->m_server)
return;
try // Some crashes during cleanup if menu doesn't exist any more
//CW@2007 : this does oddly not work in service mode - so added if handler
{
CheckForActiveConnections();
if(!menu->m_server->GetServerMode() && menu->m_server->AuthClientCount() == 0 && !isRemoteControl)
PostMessage(Hwnd(), WM_SYSCOMMAND, SC_RESTORE, 0);
}
catch(...)
{
}
}
void SessionDialog::CheckForActiveConnections()
{
if (!menu)
return;
if (!menu->m_server)
return;
try
{
HWND wnd = menu->m_server->GetHwndSessionDialog();
if(menu->m_server->AuthClientCount() != 0 || VNCviewerApp32::Instance()->ConnectionCount())
{
EnableMenuItem(GetMenu(wnd), ID_CONNECTION_CLOSE, MF_BYCOMMAND | MF_GRAYED);
EnableMenuItem(GetSystemMenu(wnd, FALSE), SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
if(GetDlgItem(wnd, IDCANCEL) != NULL)
EnableWindow(GetDlgItem(wnd, IDCANCEL), FALSE);
}
else
{
EnableMenuItem(GetMenu(wnd), ID_CONNECTION_CLOSE, MF_BYCOMMAND |MF_ENABLED);
EnableMenuItem(GetSystemMenu(wnd, FALSE), SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
HWND cancel = GetDlgItem(wnd, IDCANCEL);
if(cancel)
EnableWindow(cancel, TRUE);
else
SetLastError(0); // Do not log an error later if no cancel button exists
}
}
catch (...)
{
}
}
void SessionDialog::Hide()
{
if (!menu)
return;
if (!menu->m_server)
return;
CheckForActiveConnections();
ShowWindow(menu->m_server->GetHwndSessionDialog(),SW_HIDE);
}
void SessionDialog::SetStatus(string status)
{
if (!menu)
return;
if (!menu->m_server)
return;
if(sessionDialog->m_connectionRequested)
SetWindowText(GetDlgItem(menu->m_server->GetHwndSessionDialog(),IDC_STATUS),status.c_str());
}
void SessionDialog::ConnectionSucceded()
{
EnableControlsWhileConnecting(true);
SetStatus("");
Minimize();
sessionDialog->m_connectionRequested=false;
}
void SessionDialog::ConnectionFailed()
{
if(menu != NULL)
{
EnableControlsWhileConnecting(true);
SetStatus("");
}
sessionDialog->m_connectionRequested=false;
if(isRemoteControl)
{
Hide();
}
}
void SessionDialog::EnableControlsWhileConnecting(bool enable)
{
//EnableWindow(GetDlgItem(Hwnd(),IDC_HOSTNAME_EDIT),enable);
EnableWindow(GetDlgItem(Hwnd(),IDC_MODE_GROUP),enable);
EnableWindow(GetDlgItem(Hwnd(),IDC_MODE_TEAMWORK),enable);
EnableWindow(GetDlgItem(Hwnd(),IDC_MODE_FILETRANSFER),enable);
EnableWindow(GetDlgItem(Hwnd(),IDC_MODE_PRESENTATION),enable);
//EnableWindow(GetDlgItem(Hwnd(),IDC_TEAMWORK_TEXT),enable);
//EnableWindow(GetDlgItem(Hwnd(),IDC_REMOTECONTROL_TEXT),enable);
//EnableWindow(GetDlgItem(Hwnd(),IDC_PRESENTATION_TEXT),enable);
if(enable)
{
ShowWindow(GetDlgItem(Hwnd(),IDC_BUTTON_ABORT_CONNECTION),SW_HIDE);
ShowWindow(GetDlgItem(Hwnd(),IDOK), SW_SHOW);
}
else
{
ShowWindow(GetDlgItem(Hwnd(),IDOK), SW_HIDE);
ShowWindow(GetDlgItem(Hwnd(),IDC_BUTTON_ABORT_CONNECTION),SW_SHOW);
}
}
HWND SessionDialog::Hwnd()
{
if(menu != NULL)
return menu->m_server->GetHwndSessionDialog();
else
return NULL;
}
void SessionDialog::UpdatePassword()
{
HWND hwnd = Hwnd();
if(!hwnd)
return;
if (!menu)
return;
if (!menu->m_server)
return;
string text;
if(menu->m_properties.GeneralUseDynGate() && CroGateway::Instance()->NumericID()==0)
{
text = "";
}
else if(!menu->m_server->SockConnected())
{
text = LoadString(IDS_NO_INCOMING_CONNECTIONS);
}
else if(strlen(SessionDialog::quickSupportPassword) > 0)
{
text = "****";
}
else if(!menu->m_server->GetServerMode())
{
text = menu->m_server->SessionPassword();
}
else
{
text = LoadString(IDS_NO_SESSION_PASSWORD);
}
SetDlgItemText(hwnd,IDC_SESSION_PASSWORD,text.c_str());
}
void SessionDialog::Show()
{
if(!IsWindowVisible(Hwnd()))
{
ShowWindow(Hwnd(),SW_SHOWNORMAL | SW_RESTORE | SW_SHOW | SW_SHOWDEFAULT | SW_MAXIMIZE);
CentreWindow(Hwnd());
menu->Show(menu->m_server->GetServerMode() || isRemoteControl);
// Upgrade-Button ausgblendet
//if(!CroGateway::Instance()->Licensed())
// ShowWindow(GetDlgItem(Hwnd(),IDC_BUTTON_UPGRADE),SW_SHOW);
//else
// ShowWindow(GetDlgItem(Hwnd(),IDC_BUTTON_UPGRADE),SW_HIDE);
}
SetForegroundWindow(Hwnd());
}
void SessionDialog::ConnectionClosed()
{
Restore();
}
LRESULT CALLBACK SessionDialog::Connect(LPVOID lpParameter)
{
if (!menu)
return 1;
SessionDialog* _this=(SessionDialog*)lpParameter;
EnableControlsWhileConnecting(false);
VNCviewerApp32::Instance()->m_options.SetActiveMode(menu->m_properties.GetConnectionMode());
bool ok = VNCviewerApp32::Instance()->NewConnection(_this->m_host_dialog,_this->m_port);
//strcpy(VNCviewerApp32::Instance()->m_options.m_clearPassword,"");
MSG msg;
while (ok && GetMessage(&msg, NULL, 0,0) )
{
if (!TheAccelKeys.TranslateAccelKeys(&msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return 0;
}
void SessionDialog::RequestConnection(string commandLine)
{
HWND hwnd=SessionDialog::Hwnd();
VNCviewerApp32::Instance()->m_options.SetFromCommandLine((LPTSTR)commandLine.c_str());
if(VNCviewerApp32::Instance()->m_options.m_port != 0 &&
VNCviewerApp32::Instance()->m_options.m_port != DISPLAY_TO_PORT(0))
{
char partner[255];
sprintf(partner, "%s:%d", VNCviewerApp32::Instance()->m_options.m_host, VNCviewerApp32::Instance()->m_options.m_port);
SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, partner);
}
else
SetDlgItemText(hwnd, IDC_HOSTNAME_EDIT, VNCviewerApp32::Instance()->m_options.m_host);
int selectedButton;
switch(VNCviewerApp32::Instance()->m_options.m_ActiveMode)
{
// TV2.0: Teamwork/Remotecontrol modes are the same now
case rfbMC_TeamworkClient:
if (menu)
menu->m_properties.SetConnectionMode(RemoteControl);
selectedButton=IDC_MODE_TEAMWORK;
break;
case rfbMC_PresentationServer:
if (menu)
menu->m_properties.SetConnectionMode(Presentation);
selectedButton=IDC_MODE_PRESENTATION;
break;
case rfbMC_FiletransferClient:
if (menu)
menu->m_properties.SetConnectionMode(Filetransfer);
selectedButton=IDC_MODE_FILETRANSFER;
break;
default:
if (menu)
menu->m_properties.SetConnectionMode(RemoteControl);
selectedButton=IDC_MODE_TEAMWORK;
break;
}
CheckRadioButton(hwnd,IDC_MODE_PRESENTATION,IDC_MODE_TEAMWORK,selectedButton);
SetForegroundWindow(Hwnd());
SendMessage(hwnd,WM_COMMAND,IDOK,(LPARAM)0);
}
void SessionDialog::DisableDynGate()
{
HWND hwnd;
CroGateway::Instance()->Shutdown();
// Display Local IP
char desktopname[MAX_COMPUTERNAME_LENGTH + 1 + 256];
int desktopnamelen = MAX_COMPUTERNAME_LENGTH + 1 + 256;
GetLocalName(desktopname, desktopnamelen);
hwnd = SessionDialog::Hwnd();
if(hwnd)
{
//ShowWindow(GetDlgItem(hwnd,IDC_BUTTON_UPGRADE),SW_HIDE);
SetDlgItemText(hwnd, IDC_MYNAME, desktopname);
KillTimer(hwnd,333);
EnableMenuItem(GetMenu(hwnd), ID_EXTRAS_ACTIVATELICENSE, MF_BYCOMMAND|MF_GRAYED);
}
}
void SessionDialog::EnableDynGate()
{
HWND hwnd;
hwnd = SessionDialog::Hwnd();
if(hwnd)
{
//if(!CroGateway::Instance()->Licensed())
// ShowWindow(GetDlgItem(hwnd,IDC_BUTTON_UPGRADE),SW_SHOW);
EnableMenuItem(GetMenu(hwnd), ID_EXTRAS_ACTIVATELICENSE, MF_BYCOMMAND|MF_ENABLED);
}
CroGateway::Instance()->BeginWaitAtMaster(true);
if (menu->m_server->AutostartSetting()>0)
CroGateway::Instance()->HostMode(true);
SetTimer(hwnd,333,1000,(TIMERPROC)SessDlgProc);
}
inline void SessionDialog::Blit(HDC dcDest, HDC dcSrc, HBITMAP bmp,
CONST RECT *paintrect, int x, int y, int w, int h)
{
RECT dest;
RECT draw = {x, y, x+w, y+h};
if(IntersectRect(&dest, &draw, paintrect))
{
SelectObject(dcSrc, bmp);
BitBlt(dcDest, dest.left, dest.top, dest.right-dest.left, dest.bottom-dest.top,
dcSrc, dest.left-x, dest.top-y, SRCCOPY);
}
}
void SessionDialog::UpdateMRU(HWND hwnd)
{
// Set up recently-used list
HWND hcombo = GetDlgItem(hwnd, IDC_HOSTNAME_EDIT);
TCHAR valname[256];
SendMessage(hcombo, CB_RESETCONTENT, 0, 0);
if(m_pMRU->NumItems() == 0)
{
// enter empty string if no mru-list is available
SendMessage(hcombo, CB_ADDSTRING, 0, (LPARAM) "");
}
else
{
for (int i = 0; i < m_pMRU->NumItems(); i++) {
m_pMRU->GetItem(i, valname, 255);
int pos = SendMessage(hcombo, CB_ADDSTRING, 0, (LPARAM) valname);
}
}
SendMessage(hcombo, CB_SETCURSEL, 0, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -