📄 vncoptions.cpp
字号:
}
_tcscpy(m_via_host, args[j]);
} else if ( SwitchMatch(args[j], _T("encoding") )) {
if (++j == i) {
ArgError(_T("No encoding specified"));
continue;
}
int enc = -1;
if (_tcsicmp(args[j], _T("raw")) == 0) {
enc = rfbEncodingRaw;
} else if (_tcsicmp(args[j], _T("rre")) == 0) {
enc = rfbEncodingRRE;
} else if (_tcsicmp(args[j], _T("corre")) == 0) {
enc = rfbEncodingCoRRE;
} else if (_tcsicmp(args[j], _T("hextile")) == 0) {
enc = rfbEncodingHextile;
} else if (_tcsicmp(args[j], _T("zlib")) == 0) {
enc = rfbEncodingZlib;
} else if (_tcsicmp(args[j], _T("tight")) == 0) {
enc = rfbEncodingTight;
} else if (_tcsicmp(args[j], _T("zlibhex")) == 0) {
enc = rfbEncodingZlibHex;
} else {
ArgError(_T("Invalid encoding specified"));
continue;
}
if (enc != -1) {
m_UseEnc[enc] = true;
m_PreferredEncoding = enc;
}
} else if ( SwitchMatch(args[j], _T("compresslevel") )) {
if (++j == i) {
ArgError(_T("No compression level specified"));
continue;
}
m_useCompressLevel = true;
if (_stscanf(args[j], _T("%d"), &m_compressLevel) != 1) {
ArgError(_T("Invalid compression level specified"));
continue;
}
} else if ( SwitchMatch(args[j], _T("quality") )) {
if (++j == i) {
ArgError(_T("No image quality level specified"));
continue;
}
if (_stscanf(args[j], _T("%d"), &m_jpegQualityLevel) != 1) {
ArgError(_T("Invalid image quality level specified"));
continue;
}
} else if ( SwitchMatch(args[j], _T("register") )) {
Register();
exit(1);
} else {
TCHAR phost[256];
if (!ParseDisplay(args[j], phost, 255, &m_port)) {
ArgError(_T("Invalid VNC server specified."));
continue;
} else {
_tcscpy(m_host, phost);
_tcscpy(m_display, args[j]);
m_connectionSpecified = true;
}
}
}
// reduce scaling factors by greatest common denominator
FixScaling();
m_scaling = (m_scale_num != 1 || m_scale_den != 1 || m_FitWindow);
// tidy up
delete [] cmd;
delete [] args;
}
void saveInt(char *name, int value, char *fname)
{
char buf[4];
sprintf(buf, "%d", value);
WritePrivateProfileString("options", name, buf, fname);
}
int readInt(char *name, int defval, char *fname)
{
return GetPrivateProfileInt("options", name, defval, fname);
}
void VNCOptions::Save(char *fname)
{
for (int i = rfbEncodingRaw; i<= LASTENCODING; i++) {
char buf[128];
sprintf(buf, "use_encoding_%d", i);
saveInt(buf, m_UseEnc[i], fname);
}
saveInt("preferred_encoding", m_PreferredEncoding,fname);
saveInt("restricted", m_restricted, fname);
saveInt("viewonly", m_ViewOnly, fname);
saveInt("fullscreen", m_FullScreen, fname);
saveInt("8bit", m_Use8Bit, fname);
saveInt("shared", m_Shared, fname);
saveInt("swapmouse", m_SwapMouse, fname);
saveInt("belldeiconify", m_DeiconifyOnBell, fname);
saveInt("emulate3", m_Emul3Buttons, fname);
saveInt("emulate3timeout", m_Emul3Timeout, fname);
saveInt("emulate3fuzz", m_Emul3Fuzz, fname);
saveInt("disableclipboard", m_DisableClipboard, fname);
saveInt("localcursor", m_localCursor, fname);
saveInt("fitwindow", m_FitWindow, fname);
saveInt("scale_den", m_scale_den, fname);
saveInt("scale_num", m_scale_num, fname);
saveInt("cursorshape", m_requestShapeUpdates, fname);
saveInt("noremotecursor", m_ignoreShapeUpdates, fname);
saveInt("compresslevel", m_useCompressLevel? m_compressLevel : -1, fname);
saveInt("quality", m_enableJpegCompression? m_jpegQualityLevel : -1, fname);
}
void VNCOptions::Load(char *fname)
{
for (int i = rfbEncodingRaw; i<= LASTENCODING; i++) {
char buf[128];
sprintf(buf, "use_encoding_%d", i);
m_UseEnc[i] = readInt(buf, m_UseEnc[i], fname) != 0;
}
m_PreferredEncoding = readInt("preferred_encoding", m_PreferredEncoding, fname);
m_restricted = readInt("restricted", m_restricted, fname) != 0 ;
m_ViewOnly = readInt("viewonly", m_ViewOnly, fname) != 0;
m_FullScreen = readInt("fullscreen", m_FullScreen, fname) != 0;
m_Use8Bit = readInt("8bit", m_Use8Bit, fname) != 0;
m_Shared = readInt("shared", m_Shared, fname) != 0;
m_SwapMouse = readInt("swapmouse", m_SwapMouse, fname) != 0;
m_DeiconifyOnBell = readInt("belldeiconify", m_DeiconifyOnBell, fname) != 0;
m_Emul3Buttons = readInt("emulate3", m_Emul3Buttons, fname) != 0;
m_Emul3Timeout = readInt("emulate3timeout", m_Emul3Timeout, fname);
m_Emul3Fuzz = readInt("emulate3fuzz", m_Emul3Fuzz, fname);
m_DisableClipboard = readInt("disableclipboard", m_DisableClipboard, fname) != 0;
m_localCursor = readInt("localcursor", m_localCursor, fname);
m_FitWindow = readInt("fitwindow", m_FitWindow, fname) != 0;
m_scale_den = readInt("scale_den", m_scale_den, fname);
m_scale_num = readInt("scale_num", m_scale_num, fname);
m_requestShapeUpdates = readInt("cursorshape", m_requestShapeUpdates, fname) != 0;
m_ignoreShapeUpdates = readInt("noremotecursor", m_ignoreShapeUpdates, fname) != 0;
int level = readInt("compresslevel", -1, fname);
m_useCompressLevel = false;
if (level != -1) {
m_useCompressLevel = true;
m_compressLevel = level;
}
level = readInt("quality", 6, fname);
m_enableJpegCompression = true;
if (level == -1) {
m_enableJpegCompression = false;
} else {
m_jpegQualityLevel = level;
}
}
// Record the path to the VNC viewer and the type
// of the .vnc files in the registry
void VNCOptions::Register()
{
char keybuf[_MAX_PATH * 2 + 20];
HKEY hKey, hKey2;
if ( RegCreateKey(HKEY_CLASSES_ROOT, ".vnc", &hKey) == ERROR_SUCCESS ) {
RegSetValue(hKey, NULL, REG_SZ, "VncViewer.Config", 0);
RegCloseKey(hKey);
} else {
vnclog.Print(0, "Failed to register .vnc extension\n");
}
char filename[_MAX_PATH];
if (GetModuleFileName(NULL, filename, _MAX_PATH) == 0) {
vnclog.Print(0, "Error getting vncviewer filename\n");
return;
}
vnclog.Print(2, "Viewer is %s\n", filename);
if ( RegCreateKey(HKEY_CLASSES_ROOT, "VncViewer.Config", &hKey) == ERROR_SUCCESS ) {
RegSetValue(hKey, NULL, REG_SZ, "VNCviewer Config File", 0);
if ( RegCreateKey(hKey, "DefaultIcon", &hKey2) == ERROR_SUCCESS ) {
sprintf(keybuf, "%s,0", filename);
RegSetValue(hKey2, NULL, REG_SZ, keybuf, 0);
RegCloseKey(hKey2);
}
if ( RegCreateKey(hKey, "Shell\\open\\command", &hKey2) == ERROR_SUCCESS ) {
sprintf(keybuf, "\"%s\" -config \"%%1\"", filename);
RegSetValue(hKey2, NULL, REG_SZ, keybuf, 0);
RegCloseKey(hKey2);
}
RegCloseKey(hKey);
}
if ( RegCreateKey(HKEY_LOCAL_MACHINE,
"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\vncviewer.exe",
&hKey) == ERROR_SUCCESS ) {
RegSetValue(hKey, NULL, REG_SZ, filename, 0);
RegCloseKey(hKey);
}
}
// The dialog box allows you to change the session-specific parameters
int VNCOptions::DoDialog(bool running)
{
m_running = running;
return DialogBoxParam(pApp->m_instance, DIALOG_MAKEINTRESOURCE(IDD_PARENT),
NULL, (DLGPROC) DlgProc, (LONG) this);
}
BOOL CALLBACK VNCOptions::DlgProc(HWND hwndDlg, 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!
VNCOptions *_this = (VNCOptions *) GetWindowLong(hwndDlg, GWL_USERDATA);
switch (uMsg) {
case WM_INITDIALOG:
{
// Retrieve the Dialog box parameter and use it as a pointer
// to the calling VNCOptions object
SetWindowLong(hwndDlg, GWL_USERDATA, lParam);
VNCOptions *_this = (VNCOptions *) lParam;
InitCommonControls();
CentreWindow(hwndDlg);
_this->m_hParent = hwndDlg;
_this->m_hTab = GetDlgItem(hwndDlg, IDC_TAB);
TCITEM item;
item.mask = TCIF_TEXT;
item.pszText="Connection";
TabCtrl_InsertItem(_this->m_hTab, 0, &item);
item.pszText = "Globals";
TabCtrl_InsertItem(_this->m_hTab, 1, &item);
_this->m_hPageConnection = CreateDialogParam(pApp->m_instance,
MAKEINTRESOURCE(IDD_OPTIONDIALOG),
hwndDlg,
(DLGPROC)_this->DlgProcConnOptions,
(LONG)_this);
_this->m_hPageGeneral = CreateDialogParam(pApp->m_instance,
MAKEINTRESOURCE(IDD_GENERAL_OPTION),
hwndDlg,
(DLGPROC)_this->DlgProcGlobalOptions,
(LONG)_this);
// Position child dialogs, to fit the Tab control's display area
RECT rc;
GetWindowRect(_this->m_hTab, &rc);
MapWindowPoints(NULL, hwndDlg, (POINT *)&rc, 2);
TabCtrl_AdjustRect(_this->m_hTab, FALSE, &rc);
SetWindowPos(_this->m_hPageConnection, HWND_TOP, rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top,
SWP_SHOWWINDOW);
SetWindowPos(_this->m_hPageGeneral, HWND_TOP, rc.left, rc.top,
rc.right - rc.left, rc.bottom - rc.top,
SWP_HIDEWINDOW);
return TRUE;
}
case WM_HELP:
help.Popup(lParam);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
case IDOK:
SetFocus(GetDlgItem(hwndDlg, IDOK));
SendMessage(_this->m_hPageConnection, WM_COMMAND, IDC_OK, 0);
SendMessage(_this->m_hPageGeneral, WM_COMMAND, IDC_OK, 0);
EndDialog(hwndDlg, TRUE);
return TRUE;
case IDCANCEL:
EndDialog(hwndDlg, FALSE);
return TRUE;
}
return FALSE;
case WM_NOTIFY:
{
LPNMHDR pn = (LPNMHDR)lParam;
switch (pn->code) {
case TCN_SELCHANGE:
switch (pn->idFrom) {
case IDC_TAB:
int i = TabCtrl_GetCurFocus(_this->m_hTab);
switch (i) {
case 0:
ShowWindow(_this->m_hPageConnection, SW_SHOW);
SetFocus(_this->m_hPageConnection);
return 0;
case 1:
ShowWindow(_this->m_hPageGeneral, SW_SHOW);
SetFocus(_this->m_hPageGeneral);
return 0;
}
return 0;
}
return 0;
case TCN_SELCHANGING:
switch (pn->idFrom) {
case IDC_TAB:
int i = TabCtrl_GetCurFocus(_this->m_hTab);
switch (i) {
case 0:
ShowWindow(_this->m_hPageConnection, SW_HIDE);
break;
case 1:
ShowWindow(_this->m_hPageGeneral, SW_HIDE);
break;
}
return 0;
}
return 0;
}
return 0;
}
}
return 0;
}
static COMBOSTRING rfbcombo[MAX_LEN_COMBO] = {
"Raw",rfbEncodingRaw,
"Hextile",rfbEncodingHextile,
"Tight",rfbEncodingTight,
"RRE",rfbEncodingRRE,
"CoRRE",rfbEncodingCoRRE,
"Zlib(pure)",rfbEncodingZlib,
"ZlibHex(mix)",rfbEncodingZlibHex
};
BOOL CALLBACK VNCOptions::DlgProcConnOptions(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:
VNCOptions *_this = (VNCOptions *) GetWindowLong(hwnd, GWL_USERDATA);
switch (uMsg) {
case WM_INITDIALOG:
{
SetWindowLong(hwnd, GWL_USERDATA, lParam);
VNCOptions *_this = (VNCOptions *) lParam;
// Initialise the controls
HWND hListBox = GetDlgItem(hwnd, IDC_ENCODING);
int i;
for (i = 0; i <= (MAX_LEN_COMBO - 1); i++) {
SendMessage(hListBox, CB_INSERTSTRING,
(WPARAM)i,
(LPARAM)(int FAR*)rfbcombo[i].NameString);
if (rfbcombo[i].rfbEncoding == _this->m_PreferredEncoding) {
SendMessage(hListBox, CB_SETCURSEL, i, 0);
}
}
HWND hCopyRect = GetDlgItem(hwnd, ID_SESSION_SET_CRECT);
SendMessage(hCopyRect, BM_SETCHECK, _this->m_UseEnc[rfbEncodingCopyRect], 0);
HWND hSwap = GetDlgItem(hwnd, ID_SESSION_SWAPMOUSE);
SendMessage(hSwap, BM_SETCHECK, _this->m_SwapMouse, 0);
HWND hDeiconify = GetDlgItem(hwnd, IDC_BELLDEICONIFY);
SendMessage(hDeiconify, BM_SETCHECK, _this->m_DeiconifyOnBell, 0);
#ifndef UNDER_CE
HWND hDisableClip = GetDlgItem(hwnd, IDC_DISABLECLIPBOARD);
SendMessage(hDisableClip, BM_SETCHECK, _this->m_DisableClipboard, 0);
#endif
HWND h8bit = GetDlgItem(hwnd, IDC_8BITCHECK);
SendMessage(h8bit, BM_SETCHECK, _this->m_Use8Bit, 0);
HWND hShared = GetDlgItem(hwnd, IDC_SHARED);
SendMessage(hShared, BM_SETCHECK, _this->m_Shared, 0);
EnableWindow(hShared, !_this->m_running);
HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY);
SendMessage(hViewOnly, BM_SETCHECK, _this->m_ViewOnly, 0);
char scalecombo[8][20] = {
"25","50","75","90","100","125","150","Auto"
};
HWND hScalEdit = GetDlgItem(hwnd, IDC_SCALE_EDIT);
for (i = 0; i <= 7; i++) {
SendMessage(hScalEdit, CB_INSERTSTRING, (WPARAM)i,
(LPARAM)(int FAR*)scalecombo[i]);
}
if (_this->m_FitWindow) {
SetDlgItemText(hwnd, IDC_SCALE_EDIT, "Auto");
} else {
SetDlgItemInt(hwnd, IDC_SCALE_EDIT, (( _this->m_scale_num*100) / _this->m_scale_den), FALSE);
}
#ifndef UNDER_CE
HWND hFullScreen = GetDlgItem(hwnd, IDC_FULLSCREEN);
SendMessage(hFullScreen, BM_SETCHECK, _this->m_FullScreen, 0);
HWND hEmulate = GetDlgItem(hwnd, IDC_EMULATECHECK);
SendMessage(hEmulate, BM_SETCHECK, _this->m_Emul3Buttons, 0);
#endif
EnableWindow(hSwap,!_this->m_ViewOnly);
EnableWindow(hEmulate,!_this->m_ViewOnly);
HWND hAllowCompressLevel = GetDlgItem(hwnd, IDC_ALLOW_COMPRESSLEVEL);
SendMessage(hAllowCompressLevel, BM_SETCHECK, _this->m_useCompressLevel, 0);
HWND hAllowJpeg = GetDlgItem(hwnd, IDC_ALLOW_JPEG);
SendMessage(hAllowJpeg, BM_SETCHECK, _this->m_enableJpegCompression, 0);
EnableWindow(hAllowCompressLevel, ((_this->m_PreferredEncoding == rfbEncodingTight) ||
(_this->m_PreferredEncoding == rfbEncodingZlib) ||
(_this->m_PreferredEncoding == rfbEncodingZlibHex)));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -