⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vncacceptdialog.cpp

📁 teamviewer source code vc++
💻 CPP
字号:
//  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.


// vncAcceptDialog.cpp: implementation of the vncAcceptDialog class, used
// to query whether or not to accept incoming connections.

#include "stdhdrs.h"
#include "vncAcceptDialog.h"
#include "vncService.h"
#include "vncclient.h"
#include "vncserver.h"

#include "rores/resource.h"

#include "localization.h" // Act : add localization on messages

#define WM_AFTER_INITDIALOG WM_USER + 10000



// Constructor

vncAcceptDialog::vncAcceptDialog(vncClient *client, UINT timeoutSecs, BOOL acceptOnTimeout, const char *ipAddress)
{
	m_timeoutSecs = timeoutSecs;
	m_ipAddress = strdup(ipAddress);
	m_foreground_hack=FALSE;
	m_acceptOnTimeout = acceptOnTimeout;

	// TR@2004
	m_client = client;
	m_client->m_server->AcceptDialogOpen(true);
	m_acceptmode = ACCEPTMODE_CONNECTION;
}

vncAcceptDialog::vncAcceptDialog(UINT timeoutSecs, BOOL acceptOnTimeout)
{
	m_timeoutSecs = timeoutSecs;

	m_foreground_hack=FALSE;
	m_acceptOnTimeout = acceptOnTimeout;

	// TR@2004
	m_client = NULL;
	m_ipAddress = NULL;
	m_acceptmode = ACCEPTMODE_FILETRANSFER;
}

// Destructor

vncAcceptDialog::~vncAcceptDialog()
{
	if (m_ipAddress)
		free(m_ipAddress);

	if (m_client)
		m_client->m_server->AcceptDialogOpen(false);
}

// Routine called to activate the dialog and, once it's done, delete it

AcceptDialogResult vncAcceptDialog::DoDialog()
{
	int retVal;

	//if (m_acceptmode == ACCEPTMODE_CONNECTION)
	//{
	//	retVal = DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_ACCEPT_CONN), 
	//		NULL, (DLGPROC) vncAcceptDlgProc, (LONG) this);
	//}
	//else
	{
		retVal = DialogBoxParam(hAppInstance, MAKEINTRESOURCE(IDD_ACCEPT_FILETRANSFER), 
			NULL, (DLGPROC) vncAcceptDlgProc, (LONG) this);
	}

	delete this;
	////// Staudenmeyer
	//switch (retVal) 
	//{
	//	case IDREJECT:
	//		return 0;
	//	case IDACCEPT:
	//		return 1;
	//}
	//return (m_acceptOnTimeout) ? 1 : 0;
	return (AcceptDialogResult)retVal;

}

// Callback function - handles messages sent to the dialog box

BOOL CALLBACK vncAcceptDialog::vncAcceptDlgProc(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:
	vncAcceptDialog *_this = (vncAcceptDialog *) GetWindowLong(hwnd, GWL_USERDATA);

	switch (uMsg) {

		// Dialog has just been created
	case WM_INITDIALOG:
		{
			// Save the lParam into our user data so that subsequent calls have
			// access to the parent C++ object

            SetWindowLong(hwnd, GWL_USERDATA, lParam);
            vncAcceptDialog *_this = (vncAcceptDialog *) lParam;

			// TR@2003 - display desktop name
			/* char desktopname[MAX_COMPUTERNAME_LENGTH + 1 + 256];
			int desktopnamelen = MAX_COMPUTERNAME_LENGTH + 1 + 256;
			GetLocalName(desktopname, desktopnamelen);
			SetDlgItemText(hwnd, IDC_MYNAME, desktopname); */

			if (_this->m_acceptmode == ACCEPTMODE_CONNECTION)
				// Set the IP-address string
				SetDlgItemText(hwnd, IDC_ACCEPT_IP, _this->m_ipAddress);

			if (SetTimer(hwnd, 1, 1000, NULL) == 0)
			{
				if (_this->m_acceptOnTimeout)
					EndDialog(hwnd, AcceptWithTimeout);
					//EndDialog(hwnd, IDACCEPT);
				else
				EndDialog(hwnd, Reject);
				//EndDialog(hwnd, IDREJECT);
			}
			_this->m_timeoutCount = _this->m_timeoutSecs;

			char temp[256];
			if (_this->m_acceptOnTimeout)
				sprintf(temp, "AutoAccept:%u", (_this->m_timeoutCount));
			else
				sprintf(temp, "AutoReject:%u", (_this->m_timeoutCount));
			SetDlgItemText(hwnd, IDC_ACCEPT_TIMEOUT, temp);


			// Attempt to mimic Win98/2000 dialog behaviour
			if ((vncService::IsWinNT() && (vncService::VersionMajor() <= 4)) ||
				(vncService::IsWin95() && (vncService::VersionMinor() == 0)))
			{
				// Perform special hack to display the dialog safely
				if (GetWindowThreadProcessId(GetForegroundWindow(), NULL) != GetCurrentProcessId())
				{
					// We can't set our dialog as foreground if the foreground window
					// doesn't belong to us - it's unsafe!
					SetActiveWindow(hwnd);
					_this->m_foreground_hack = TRUE;
					_this->m_flash_state = FALSE;
				}
			}
			if (!_this->m_foreground_hack) {
				SetForegroundWindow(hwnd);
			}

			// Beep
			MessageBeep(MB_ICONEXCLAMATION);
			PostMessage(hwnd,WM_AFTER_INITDIALOG,0,0);
	
			// Return success!
			return TRUE;
		}
	///////// Staudenmeyer:
	case WM_AFTER_INITDIALOG:
		if(_this->m_acceptOnTimeout)
		{
			// Reset the current default push button to a regular button.
			SendDlgItemMessage(hwnd,IDREJECT,
					BM_SETSTYLE, BS_PUSHBUTTON, (LONG)TRUE);

			// Update the default push button's control ID.
			SendMessage(hwnd, DM_SETDEFID, IDACCEPT,
					0L);

			// Set the new style.
			SendDlgItemMessage(hwnd, IDACCEPT,
					BM_SETSTYLE, BS_DEFPUSHBUTTON, (LONG)TRUE); 
		}
		break;
	////////

		// Timer event
	case WM_TIMER:
		if ((_this->m_timeoutCount) == 0)
			{
				if ( _this->m_acceptOnTimeout ) 
					{
						EndDialog(hwnd, AcceptWithTimeout);
						//EndDialog(hwnd, IDACCEPT);
					}
				else 
					{
						EndDialog(hwnd, Reject);
						//EndDialog(hwnd, IDREJECT);
					}
			}
		_this->m_timeoutCount--;

		// Flash if necessary
		if (_this->m_foreground_hack) {
			if (GetWindowThreadProcessId(GetForegroundWindow(), NULL) != GetCurrentProcessId())
			{
				_this->m_flash_state = !_this->m_flash_state;
				FlashWindow(hwnd, _this->m_flash_state);
			} else {
				_this->m_foreground_hack = FALSE;
			}
		}

		// Update the displayed count
		char temp[256];
		if ( _this->m_acceptOnTimeout )
			sprintf(temp, sz_IDS_ACCEPTDIALOG_ACCEPT, (_this->m_timeoutCount));
		else
			sprintf(temp, sz_IDS_ACCEPTDIALOG_REJECT, (_this->m_timeoutCount));
		SetDlgItemText(hwnd, IDC_ACCEPT_TIMEOUT, temp);
		break;

		// Dialog has just received a command
	case WM_COMMAND:
		switch (LOWORD(wParam)) {

			// User clicked Accept or pressed return
		case IDACCEPT:
		case IDOK:
			EndDialog(hwnd, Accept);
			//EndDialog(hwnd, IDACCEPT);
			return TRUE;

		case IDREJECT:
		case IDCANCEL:
			EndDialog(hwnd, Reject);
			//EndDialog(hwnd, IDREJECT);
			return TRUE;
		};

		break;

		// Window is being destroyed!  (Should never happen)
	case WM_DESTROY:
		EndDialog(hwnd, Reject);
		//EndDialog(hwnd, IDREJECT);
		return TRUE;
	case WM_ERASEBKGND:
		return EraseBkgnd(hwnd, wParam);
	case WM_CTLCOLORBTN:
		return CtlColorBtn(wParam);
	case WM_CTLCOLORSTATIC:
		return CtlColorStatic(hwnd, wParam, lParam);

	}
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -