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

📄 vncoptions.cpp

📁 tightvnc源码
💻 CPP
📖 第 1 页 / 共 4 页
字号:
				char buf[80];
				HWND hMessage = GetDlgItem(hwnd, IDC_CHECK_MESSAGE);
				HWND hToolbar = GetDlgItem(hwnd, IDC_CHECK_TOOLBAR);
				HWND hChec = GetDlgItem(hwnd, IDC_CHECK_LOG_FILE);

				if (SendMessage(hDotCursor, BM_GETCHECK, 0, 0) == BST_CHECKED) {
					pApp->m_options.m_localCursor = DOTCURSOR;
					SetClassLong(_this->m_hWindow, GCL_HCURSOR,
									(long)LoadCursor(pApp->m_instance, 
									MAKEINTRESOURCE(IDC_DOTCURSOR)));
				}
				if (SendMessage(hSmallCursor, BM_GETCHECK, 0, 0) == BST_CHECKED) {
					pApp->m_options.m_localCursor = SMALLCURSOR;
					SetClassLong(_this->m_hWindow, GCL_HCURSOR,
									(long)LoadCursor(pApp->m_instance, 
									MAKEINTRESOURCE(IDC_SMALLDOT)));
				}
				if (SendMessage(hNoCursor, BM_GETCHECK, 0, 0) == BST_CHECKED) {
					pApp->m_options.m_localCursor = NOCURSOR;
					SetClassLong(_this->m_hWindow, GCL_HCURSOR,
									(long)LoadCursor(pApp->m_instance, 
									MAKEINTRESOURCE(IDC_NOCURSOR)));
				}
				if (SendMessage(hNormalCursor, BM_GETCHECK, 0, 0) == BST_CHECKED) {
					pApp->m_options.m_localCursor = NORMALCURSOR;
					SetClassLong(_this->m_hWindow, GCL_HCURSOR,
									(long)LoadCursor(NULL,IDC_ARROW));
				}
				
				if (SendMessage(hChec, BM_GETCHECK, 0, 0) == 0) {
					pApp->m_options.m_logToFile = false;
				} else {
					pApp->m_options.m_logToFile = true;
					pApp->m_options.m_logLevel = GetDlgItemInt(hwnd,
						IDC_EDIT_LOG_LEVEL, NULL, FALSE);
					GetDlgItemText(hwnd, IDC_EDIT_LOG_FILE,
						buf, 80); 
					strcpy(pApp->m_options.m_logFilename, buf);
					
					vnclog.SetLevel(pApp->m_options.m_logLevel);
					vnclog.SetFile(pApp->m_options.m_logFilename);
				}
				
				if (SendMessage(hMessage, BM_GETCHECK, 0, 0) == 0) {
					pApp->m_options.m_skipprompt = true;
				} else {
					pApp->m_options.m_skipprompt = false;
				}				
				if (SendMessage(hToolbar, BM_GETCHECK, 0, 0) == 0) {
					pApp->m_options.m_toolbar = false;					
				} else {
					pApp->m_options.m_toolbar = true;					
				}
				
				pApp->m_options.m_historyLimit = GetDlgItemInt(hwnd,
					IDC_EDIT_AMOUNT_LIST, NULL, FALSE);
				pApp->m_options.m_listenPort = GetDlgItemInt(hwnd,
					IDC_LISTEN_PORT, NULL, FALSE);
				pApp->m_options.SaveGenOpt();

				return 0;
			}
		case IDC_CHECK_LOG_FILE:
			switch (HIWORD(wParam)) {
			case BN_CLICKED:				
				HWND hChec = GetDlgItem(hwnd, IDC_CHECK_LOG_FILE);				
				if (SendMessage(hChec, BM_GETCHECK, 0, 0) == 0){
					_this->EnableLog(hwnd, TRUE);					
					SendMessage(hChec, BM_SETCHECK, TRUE, 0);
				} else {
					_this->EnableLog(hwnd, FALSE);
					SendMessage(hChec, BM_SETCHECK, FALSE, 0);
				} 
				return 0;
			}
		}
		return 0;				
	case WM_NOTIFY: 
		{		
			LPNMHDR pn = (LPNMHDR)lParam;
			switch (pn->code) {
			case UDN_DELTAPOS: 
				{	int max, min;
					NMUPDOWN lpnmud = *(LPNMUPDOWN) lParam;
					NMHDR hdr = lpnmud.hdr;
					HWND hCtrl = (HWND)SendMessage(hdr.hwndFrom, UDM_GETBUDDY, 0, 0);
					long ctrl = GetDlgCtrlID(hCtrl);
					int h = GetDlgItemInt( hwnd, ctrl, NULL, TRUE);
					if (lpnmud.iDelta > 0) {
						if (h != 0) {
							h = h - 1;
						}
					} else {
						h = h + 1;	
					}
					SetDlgItemInt( hwnd, ctrl, h, FALSE);
					switch (ctrl) {
					case IDC_EDIT_AMOUNT_LIST:
						min = 0;
						max = 64;
						break;
					case IDC_EDIT_LOG_LEVEL:
						min = 0;
						max = 12;
						break;
					case IDC_LISTEN_PORT:
						min = 1;
						max = 65536;
						break;
					}
					_this->Lim(hwnd, ctrl, min, max);
					return 0;
				}			
			}
			return 0;
		}
	}
	return 0;
}

void VNCOptions::EnableLog(HWND hwnd, bool enable)
{
	HWND hlevel = GetDlgItem(hwnd, IDC_STATIC_LOG_LEVEL);
	HWND hEditFile = GetDlgItem(hwnd, IDC_EDIT_LOG_FILE);
	HWND hEditLevel = GetDlgItem(hwnd, IDC_EDIT_LOG_LEVEL);
	HWND hLogBrowse = GetDlgItem(hwnd, IDC_LOG_BROWSE);
	
	EnableWindow(hEditFile, enable);
	EnableWindow(hEditLevel, enable);
	EnableWindow(hlevel, enable);
	EnableWindow(hLogBrowse, enable);
}

void VNCOptions::Lim(HWND hwnd, int control, DWORD min, DWORD max)
{
	DWORD buf;
	int error;
	buf=GetDlgItemInt(hwnd, control,
					&error, FALSE);
	if (buf > max && error) {
		buf = max;
		SetDlgItemInt(hwnd, control,
					buf, FALSE);
	}
	if (buf < min && error) {
		buf = min;
		SetDlgItemInt(hwnd, control,
					buf, FALSE);
	}
}

void VNCOptions::LoadOpt(char subkey[256], char keyname[256])
{
	HKEY RegKey;
	TCHAR key[80];
	_tcscpy(key, keyname);
	_tcscat(key, "\\");
	_tcscat(key, subkey);
	 RegOpenKeyEx(HKEY_CURRENT_USER, key, 0,  
		 KEY_ALL_ACCESS,  &RegKey);
	for (int i = rfbEncodingRaw; i <= LASTENCODING; i++) {
		char buf[128];
		sprintf(buf, "use_encoding_%d", i);
		m_UseEnc[i] =   read(RegKey, buf, m_UseEnc[i] ) != 0;
	}
	m_PreferredEncoding =	read(RegKey, "preferred_encoding",m_PreferredEncoding    );
	m_restricted =			read(RegKey, "restricted",        m_restricted           ) != 0;
	m_ViewOnly =			read(RegKey, "viewonly",	      m_ViewOnly             ) != 0;
	m_FullScreen =			read(RegKey, "fullscreen",        m_FullScreen           ) != 0;
	m_Use8Bit =				read(RegKey, "8bit",	          m_Use8Bit              ) != 0;
	m_Shared =				read(RegKey, "shared",            m_Shared               ) != 0;
	m_SwapMouse =			read(RegKey, "swapmouse",         m_SwapMouse	         ) != 0;
	m_DeiconifyOnBell =		read(RegKey, "belldeiconify",     m_DeiconifyOnBell      ) != 0;
	m_Emul3Buttons =		read(RegKey, "emulate3",	      m_Emul3Buttons         ) != 0;
	m_Emul3Timeout =		read(RegKey, "emulate3timeout",   m_Emul3Timeout         );
	m_Emul3Fuzz =			read(RegKey, "emulate3fuzz",	  m_Emul3Fuzz            );
	m_DisableClipboard =	read(RegKey, "disableclipboard",  m_DisableClipboard     ) != 0;
	m_FitWindow =			read(RegKey, "fitwindow",		  m_FitWindow		     ) != 0;
	m_scale_den =			read(RegKey, "scale_den",         m_scale_den	         );
	m_scale_num =			read(RegKey, "scale_num",         m_scale_num	         );
	m_requestShapeUpdates =	read(RegKey, "cursorshape",       m_requestShapeUpdates	 ) != 0;
	m_ignoreShapeUpdates =	read(RegKey, "noremotecursor",    m_ignoreShapeUpdates   ) != 0;
	int level		 =		read(RegKey, "compresslevel",     -1				     );
	m_useCompressLevel = false;
	if (level != -1) {
		m_compressLevel = level;
		m_useCompressLevel = true;
	}
	m_scaling =				read(RegKey, "scaling",			  m_scaling  ) != 0;	
		
	m_enableJpegCompression = true;
	level =					read(RegKey, "quality",			  6);
	if (level == -1) {
		m_enableJpegCompression = false;
	} else {
		m_jpegQualityLevel = level;
	}
	RegCloseKey(RegKey);
}

int VNCOptions::read(HKEY hkey, char *name, int retrn)
{
	DWORD buflen = 4;
	DWORD buf = 0;
	if(RegQueryValueEx(hkey ,(LPTSTR)name , 
            NULL, NULL, 
            (LPBYTE) &buf, (LPDWORD) &buflen) != ERROR_SUCCESS) {
		return retrn;
	} else {
		return buf;
	}
}

void VNCOptions::SaveOpt(char subkey[256], char keyname[256])
{
	DWORD dispos;
	HKEY RegKey;
	TCHAR key[80];
	_tcscpy(key, keyname);
	_tcscat(key, "\\");
	_tcscat(key, subkey);
	RegCreateKeyEx(HKEY_CURRENT_USER, key, 0, NULL, 
		REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &RegKey, &dispos);
	for (int i = rfbEncodingRaw; i <= LASTENCODING; i++) {
		char buf[128];
		sprintf(buf, "use_encoding_%d", i);
		save(RegKey, buf, m_UseEnc[i] );
	}
	save(RegKey, "preferred_encoding",	m_PreferredEncoding);
	save(RegKey, "restricted",			m_restricted		);
	save(RegKey, "viewonly",			m_ViewOnly			);
	save(RegKey, "fullscreen",			m_FullScreen		);
	save(RegKey, "scaling",				m_scaling			);
	save(RegKey, "8bit",				m_Use8Bit			);
	save(RegKey, "shared",				m_Shared			);
	save(RegKey, "swapmouse",			m_SwapMouse			);
	save(RegKey, "belldeiconify",		m_DeiconifyOnBell	);
	save(RegKey, "emulate3",			m_Emul3Buttons		);
	save(RegKey, "emulate3timeout",		m_Emul3Timeout		);
	save(RegKey, "emulate3fuzz",		m_Emul3Fuzz			);
	save(RegKey, "disableclipboard",	m_DisableClipboard  );
	save(RegKey, "fitwindow",			m_FitWindow			);
	save(RegKey, "scale_den",			m_scale_den			);
	save(RegKey, "scale_num",			m_scale_num			);
	save(RegKey, "cursorshape",			m_requestShapeUpdates );
	save(RegKey, "noremotecursor",		m_ignoreShapeUpdates );	
	save(RegKey, "compresslevel", m_useCompressLevel ? m_compressLevel : -1);	
	save(RegKey, "quality",	m_enableJpegCompression ? m_jpegQualityLevel : -1);
	
	
	RegCloseKey(RegKey);
}

void VNCOptions::delkey(char subkey[256], char keyname[256])
{
		
	TCHAR key[80];
	_tcscpy(key, keyname);
	_tcscat(key, "\\");
	_tcscat(key, subkey);
	RegDeleteKey (HKEY_CURRENT_USER, key);
}

void VNCOptions::save(HKEY hkey, char *name, int value) 
{
	RegSetValueEx( hkey, name, 
            NULL, REG_DWORD, 
            (CONST BYTE *)&value, 4);
}

void VNCOptions::LoadGenOpt()
{
	HKEY hRegKey;
		
	if ( RegOpenKey(HKEY_CURRENT_USER,
					SETTINGS_KEY_NAME, &hRegKey) != ERROR_SUCCESS ) {
		hRegKey = NULL;
	} else {
		DWORD buffer;
		DWORD buffersize = sizeof(buffer);
		DWORD valtype;
		if ( RegQueryValueEx( hRegKey, "SkipFullScreenPrompt", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {			
			m_skipprompt = buffer == 1;				
		}		
		if ( RegQueryValueEx( hRegKey, "NoToolbar", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {
			m_toolbar = buffer == 1;
		}
		if ( RegQueryValueEx( hRegKey, "LogToFile", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {
				m_logToFile = buffer == 1;
		}
		if ( RegQueryValueEx( hRegKey, "HistoryLimit", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {
			m_historyLimit = buffer;
		}
		if ( RegQueryValueEx( hRegKey, "LocalCursor", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {
			m_localCursor = buffer;
		}
		if ( RegQueryValueEx( hRegKey, "LogLevel", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {
			m_logLevel = buffer;
		}
		if ( RegQueryValueEx( hRegKey, "ListenPort", NULL, &valtype, 
				(LPBYTE)&buffer, &buffersize) == ERROR_SUCCESS) {
			m_listenPort = buffer;
		}
		TCHAR buf[_MAX_PATH];
		buffersize=_MAX_PATH;
		if (RegQueryValueEx( hRegKey, "LogFileName", NULL, &valtype, 
				(LPBYTE) &buf, &buffersize) == ERROR_SUCCESS) {
			strcpy(m_logFilename, buf);
		}
		RegCloseKey(hRegKey);
	}	
}

void VNCOptions::SaveGenOpt()
{
	HKEY hRegKey;
	DWORD buffer;
	TCHAR buf[80];

	RegCreateKey(HKEY_CURRENT_USER,
					SETTINGS_KEY_NAME, &hRegKey);
	RegSetValueEx( hRegKey, "LocalCursor", 
					NULL, REG_DWORD, 
					(CONST BYTE *)&m_localCursor,
					4);
				
	RegSetValueEx( hRegKey, "HistoryLimit", 
					NULL, REG_DWORD, 
					(CONST BYTE *)&m_historyLimit,
					4);
				
	RegSetValueEx( hRegKey, "LogLevel", 
					NULL, REG_DWORD, 
					(CONST BYTE *)&m_logLevel,
					4);
				
	strcpy(buf, m_logFilename);
	RegSetValueEx( hRegKey, "LogFileName", 
					NULL, REG_SZ , 
					(CONST BYTE *)buf, (_tcslen(buf)+1));				
				
	RegSetValueEx( hRegKey, "ListenPort", 
					NULL, REG_DWORD, 
					(CONST BYTE *)&m_listenPort,
					4);
	if (m_logToFile) {
		buffer = 1;
	} else {
		buffer = 0;
	}
	RegSetValueEx( hRegKey, "LogToFile" , 
					NULL, REG_DWORD, 
					(CONST BYTE *)&buffer,
					4);
	if (m_skipprompt) {
		buffer = 1;
	} else {
		buffer = 0;
	}
	RegSetValueEx( hRegKey, "SkipFullScreenPrompt", 
					NULL,REG_DWORD, 
					(CONST BYTE *)&buffer,
					4);
	if (m_toolbar) {
		buffer = 1;
	} else {
		buffer = 0;
	}
	RegSetValueEx( hRegKey, "NoToolbar", 
					NULL, REG_DWORD, 
					(CONST BYTE *)&buffer,
					4);
				
	RegCloseKey(hRegKey);
}

void VNCOptions::BrowseLogFile()
{
	OPENFILENAME ofn;
	char filter[] = "Log files (*.log)\0*.log\0" \
						   "All files (*.*)\0*.*\0";
	char tname[_MAX_FNAME + _MAX_EXT];
	memset((void *) &ofn, 0, sizeof(OPENFILENAME));
	ofn.lStructSize = sizeof(OPENFILENAME);
	ofn.lpstrFilter = filter;
	ofn.nMaxFile = _MAX_PATH;
	ofn.nMaxFileTitle = _MAX_FNAME + _MAX_EXT;
	ofn.lpstrDefExt = "log";	
	ofn.hwndOwner = m_hParent;
	ofn.lpstrFile = pApp->m_options.m_logFilename;
	ofn.lpstrFileTitle = tname;
	ofn.lpstrTitle = "Log file";
	ofn.Flags = OFN_HIDEREADONLY;
	if (!GetSaveFileName(&ofn)) {
		DWORD err = CommDlgExtendedError();
		char msg[1024]; 
		switch(err) {
		case 0:	// user cancelled
			break;
		case FNERR_INVALIDFILENAME:
			strcpy(msg, "Invalid filename");
			MessageBox(m_hParent, msg, "Error log file", MB_ICONERROR | MB_OK);
			break;
		default:
			vnclog.Print(0, "Error %d from GetSaveFileName\n", err);
			break;
		}
		return;
	}
}

⌨️ 快捷键说明

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