vncproperties.cpp

来自「Web VNC samples delphi」· C++ 代码 · 共 1,204 行 · 第 1/3 页

CPP
1,204
字号
	}
	return 0;
}

BOOL CALLBACK vncProperties::IncomingDlgProc(HWND hwnd, UINT uMsg,
                                             WPARAM wParam, LPARAM lParam)
{
	// We use the dialog-box's USERDATA to store a _this pointer
	// This is set only once WM_INITDIALOG has been recieved, though!
	vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA);
	
	switch (uMsg)
	{
	case WM_INITDIALOG:
		{
			// Retrieve the Dialog box parameter and use it as a pointer
			// to the calling vncProperties object
			SetWindowLong(hwnd, GWL_USERDATA, lParam);
			vncProperties *_this = (vncProperties *) lParam;
			_this->m_incConnCtrl = new IncomingConnectionsControls(hwnd, _this->m_server);
			_this->m_inputhandcontr = new InputHandlingControls(hwnd, _this->m_server);
			HWND hLockSetting;
			switch (_this->m_server->LockSettings()) {
			case 1:
				hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_LOCK);
				break;
			case 2:
				hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_LOGOFF);
				break;
			default:
				hLockSetting = GetDlgItem(hwnd, IDC_LOCKSETTING_NOTHING);
			}
			SendMessage(hLockSetting, BM_SETCHECK, TRUE, 0);
			return 0;
		}
	case WM_HELP:	
		VNCHelp::Popup(lParam);
		return 0;
    case WM_COMMAND:		
		switch (LOWORD(wParam))
		{
		case IDC_CONNECT_SOCK:
		case IDC_PORTNO_AUTO:
		case IDC_SPECDISPLAY:
		case IDC_SPECPORT:
			_this->m_incConnCtrl->Validate(FALSE);
			return TRUE;      
		case IDC_DISABLE_INPUTS:
		case IDC_DISABLE_LOCAL_INPUTS:			
			_this->m_inputhandcontr->EnableInputs(hwnd);				
			return TRUE;	
		case IDC_REMOTE_DISABLE:
			_this->m_inputhandcontr->EnableRemote(hwnd);
			return TRUE;
		case IDC_APPLY:
			_this->m_incConnCtrl->Apply();
			_this->m_inputhandcontr->ApplyInputsControlsContents(hwnd);
			// Lock settings handling
			if (SendMessage(GetDlgItem(hwnd, IDC_LOCKSETTING_LOCK), BM_GETCHECK, 0, 0)
				== BST_CHECKED) {
				_this->m_server->SetLockSettings(1);
			} else if (SendMessage(GetDlgItem(hwnd, IDC_LOCKSETTING_LOGOFF), BM_GETCHECK, 0, 0)
				== BST_CHECKED) {
				_this->m_server->SetLockSettings(2);
			} else {
				_this->m_server->SetLockSettings(0);
			}
			return TRUE;
		}
		return 0;
	case WM_DESTROY:
		delete _this->m_incConnCtrl;      
		_this->m_incConnCtrl = NULL;  
		delete _this->m_inputhandcontr;
		_this->m_inputhandcontr = NULL;
		_this->m_hIncoming = NULL;  
		return 0;
	}
	return 0;
}

BOOL CALLBACK vncProperties::PollDlgProc(HWND hwnd, UINT uMsg,
                                         WPARAM wParam, LPARAM lParam)
{
	// We use the dialog-box's USERDATA to store a _this pointer
	// This is set only once WM_INITDIALOG has been recieved, though!
	vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA);
	
	switch (uMsg)
	{
	case WM_INITDIALOG:
		{
			// Retrieve the Dialog box parameter and use it as a pointer
			// to the calling vncProperties object
			SetWindowLong(hwnd, GWL_USERDATA, lParam);
			vncProperties *_this = (vncProperties *) lParam;

			_this->m_pollcontrols = new PollControls(hwnd, _this->m_server); 
			return 0;
		}
	case WM_HELP:	
		VNCHelp::Popup(lParam);
		return 0;
	case WM_COMMAND:	
		switch (LOWORD(wParam))
		{
		case IDC_POLL_FOREGROUND:
		case IDC_POLL_UNDER_CURSOR:
		case IDC_POLL_FULLSCREEN:
			_this->m_pollcontrols->Validate();
			return TRUE;

		case IDOK:
		case IDC_APPLY:
			_this->m_pollcontrols->Apply();
			return TRUE;
		}
		return 0;
	case WM_DESTROY:
		delete _this->m_pollcontrols;
		_this->m_pollcontrols = NULL;  
		_this->m_hPoll = NULL;
		return 0;
	}
	return 0;
}

BOOL CALLBACK vncProperties::SharedDlgProc(HWND hwnd, UINT uMsg,
                                           WPARAM wParam, LPARAM lParam)
{
	// We use the dialog-box's USERDATA to store a _this pointer
	// This is set only once WM_INITDIALOG has been recieved, though!
	vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA);
	
	switch (uMsg)
	{
	case WM_INITDIALOG:
		{
			// Retrieve the Dialog box parameter and use it as a pointer
			// to the calling vncProperties object
			SetWindowLong(hwnd, GWL_USERDATA, lParam);
			vncProperties *_this = (vncProperties *) lParam;
			
			_this->m_shareddtarea = new SharedDesktopArea(hwnd,
				_this->m_pMatchWindow, _this->m_server);

			return 0;
		}
	case WM_HELP:	
		VNCHelp::Popup(lParam);
		return 0;
	case WM_COMMAND:	
		switch (LOWORD(wParam))
		{
		case IDC_FULLSCREEN:
		case IDC_PRIMARY_DISPLAY_ONLY:
		case IDC_SCREEN:
		case IDC_WINDOW:
			_this->m_shareddtarea->Validate();
			return TRUE;

		case IDC_APPLY:
		case IDOK:
			_this->m_shareddtarea->Apply();
			return TRUE;
		}
		return 0;

	case WM_DESTROY:
		delete _this->m_shareddtarea;
		_this->m_shareddtarea = NULL;
		_this->m_hShared = NULL;
		return 0;
	}

	return 0;
}

BOOL CALLBACK vncProperties::AdministrationDlgProc(HWND hwnd, UINT uMsg,
												  WPARAM wParam, LPARAM lParam)
{
	// We use the dialog-box's USERDATA to store a _this pointer
	// This is set only once WM_INITDIALOG has been recieved, though!
	vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA);
	
	switch (uMsg)
	{
	case WM_INITDIALOG:
		{
			// Retrieve the Dialog box parameter and use it as a pointer
			// to the calling vncProperties object
			SetWindowLong(hwnd, GWL_USERDATA, lParam);
			vncProperties *_this = (vncProperties *) lParam;
			_this->m_AdminControls = new AdministrationControls(hwnd, _this->m_server);
			return 0;
		}
	case WM_HELP:	
		VNCHelp::Popup(lParam);
		return 0;
    case WM_COMMAND:		
		switch (LOWORD(wParam))
		{
		case IDALLOWLOOPBACK:
		case IDLOG:
		case IDENABLEHTTPD:
			_this->m_AdminControls->Validate();
			return TRUE;      
		case IDC_APPLY:
			_this->m_AdminControls->Apply();
			return TRUE;
		}
		return 0;
	case WM_DESTROY:
		delete _this->m_AdminControls;      
		_this->m_AdminControls = NULL;  
		_this->m_hAdministration = NULL;  
		return 0;
	}
	return 0;	
}

BOOL CALLBACK vncProperties::QuerySettingsDlgProc(HWND hwnd, UINT uMsg,
												   WPARAM wParam, LPARAM lParam)
{
	// We use the dialog-box's USERDATA to store a _this pointer
	// This is set only once WM_INITDIALOG has been recieved, though!
	vncProperties *_this = (vncProperties *) GetWindowLong(hwnd, GWL_USERDATA);
	
	switch (uMsg)
	{
	case WM_INITDIALOG:
		{
			// Retrieve the Dialog box parameter and use it as a pointer
			// to the calling vncProperties object
			SetWindowLong(hwnd, GWL_USERDATA, lParam);
			vncProperties *_this = (vncProperties *) lParam;
			_this->m_QSControls = new QuerySettingsControls(hwnd, _this->m_server);
			return 0;
		}
	case WM_HELP:	
		VNCHelp::Popup(lParam);
		return 0;
    case WM_COMMAND:		
		switch (LOWORD(wParam))
		{
		case IDQUERY:
			_this->m_QSControls->Validate();
			return TRUE;      
		case IDC_APPLY:
			_this->m_QSControls->Apply();
			return TRUE;
		}
		return 0;
	case WM_DESTROY:
		delete _this->m_QSControls;      
		_this->m_QSControls = NULL;  
		_this->m_hQuerySettings = NULL;  
		return 0;
	}
	return 0;	
}

// Functions to load & save the settings
LONG
vncProperties::LoadInt(HKEY key, LPCSTR valname, LONG defval)
{
	LONG pref;
	ULONG type = REG_DWORD;
	ULONG prefsize = sizeof(pref);

	if (key == NULL)
		return defval;

	if (RegQueryValueEx(key,
		valname,
		NULL,
		&type,
		(LPBYTE) &pref,
		&prefsize) != ERROR_SUCCESS)
		return defval;

	if (type != REG_DWORD)
		return defval;

	if (prefsize != sizeof(pref))
		return defval;

	return pref;
}

BOOL
vncProperties::LoadPassword(HKEY key, char *buffer, const char *entry_name)
{
	DWORD type = REG_BINARY;
	int slen=MAXPWLEN;
	char inouttext[MAXPWLEN];

	if (key == NULL)
		return FALSE;

	// Retrieve the encrypted password
	if (RegQueryValueEx(key,
		(LPCSTR) entry_name,
		NULL,
		&type,
		(LPBYTE) &inouttext,
		(LPDWORD) &slen) != ERROR_SUCCESS)
		return FALSE;

	if (slen > MAXPWLEN)
		return FALSE;

	memcpy(buffer, inouttext, MAXPWLEN);
	return TRUE;
}

char *
vncProperties::LoadString(HKEY key, LPCSTR keyname)
{
	DWORD type = REG_SZ;
	DWORD buflen = 0;
	BYTE *buffer = 0;

	if (key == NULL)
		return 0;

	// Get the length of the AuthHosts string
	if (RegQueryValueEx(key,
		keyname,
		NULL,
		&type,
		NULL,
		&buflen) != ERROR_SUCCESS)
		return 0;

	if (type != REG_SZ)
		return 0;
	buffer = new BYTE[buflen];
	if (buffer == 0)
		return 0;

	// Get the AuthHosts string data
	if (RegQueryValueEx(key,
		keyname,
		NULL,
		&type,
		buffer,
		&buflen) != ERROR_SUCCESS) {
		delete [] buffer;
		return 0;
	}

	// Verify the type
	if (type != REG_SZ) {
		delete [] buffer;
		return 0;
	}

	return (char *)buffer;
}

void
vncProperties::Load(BOOL usersettings)
{
	if (m_dlgvisible) {
		vnclog.Print(LL_INTWARN, VNCLOG("service helper invoked while Properties panel displayed\n"));
		return;
	}

	char username[UNLEN+1];
	HKEY hkLocal, hkLocalUser, hkDefault;
	DWORD dw;

	// NEW (R3) PREFERENCES ALGORITHM
	// 1.	Look in HKEY_LOCAL_MACHINE/Software/ORL/WinVNC3/%username%
	//		for sysadmin-defined, user-specific settings.
	// 2.	If not found, fall back to %username%=Default
	// 3.	If AllowOverrides is set then load settings from
	//		HKEY_CURRENT_USER/Software/ORL/WinVNC3

	// GET THE CORRECT KEY TO READ FROM

	// Get the user name / service name
	if (!vncService::CurrentUser((char *)&username, sizeof(username)))
		return;

	// If there is no user logged on them default to SYSTEM
	if (strcmp(username, "") == 0)
		strcpy((char *)&username, "SYSTEM");

	// Try to get the machine registry key for WinVNC
	if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
		WINVNC_REGISTRY_KEY,
		0, REG_NONE, REG_OPTION_NON_VOLATILE,
		KEY_READ, NULL, &hkLocal, &dw) != ERROR_SUCCESS)
		hkLocal = NULL;

	// Now try to get the per-user local key
	if ( hkLocal == NULL ||
		 RegOpenKeyEx(hkLocal, username, 0,
					  KEY_READ, &hkLocalUser) != ERROR_SUCCESS )
		hkLocalUser = NULL;

⌨️ 快捷键说明

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