📄 properties.cpp
字号:
m_pref_Remote_Autoscaling = (bool)LoadInt(appkey, "RemoteControlAutoscaling", m_pref_Remote_Autoscaling);
m_pref_Remote_ScaleBy = LoadInt(appkey, "RemoteControlScaleBy", m_pref_Remote_ScaleBy);
m_pref_Remote_ShowRemoteCursor = (bool)LoadInt(appkey, "RemoteControlShowRemoteCursor", m_pref_Remote_ShowRemoteCursor);
// presentation prefs
m_pref_Presentation_Quality = LoadInt(appkey, "PresentationQuality", m_pref_Presentation_Quality);
m_pref_Presentation_Compression = LoadInt(appkey, "PresentationCompression", m_pref_Presentation_Compression);
m_pref_Presentation_Colors = LoadInt(appkey, "PresentationColors", m_pref_Presentation_Colors);
m_pref_Presentation_ServerScale = LoadInt(appkey, "PresentationServerScale", m_pref_Presentation_ServerScale);
m_pref_Presentation_SingleWindow = (bool)LoadInt(appkey, "PresentationSingleWindow", m_pref_Presentation_SingleWindow);
LoadString(appkey, "PresentationSWName", m_pref_Presentation_WindowNamed, MAX_SW_NAMELEN);
// Custom invitation using STL strings!
char s1[MAX_SUBJECT_STRING_LEN];
SecureZeroMemory(&s1,sizeof(s1));
this->LoadString(appkey, "InvitationSubject", s1, MAX_SUBJECT_STRING_LEN);
m_pref_CustomInvitation_Subject = s1;
char s2[MAX_INVITATION_TEXT_LEN*2];
SecureZeroMemory(&s2,sizeof(s2));
this->LoadString(appkey, "InvitationText", s2, sizeof(s2));
m_pref_CustomInvitation_Text = s2;
ConvertHTML2CInvitation();
if (m_pref_CustomInvitation_Subject.length() > MAX_SUBJECT_STRING_LEN)
m_pref_CustomInvitation_Subject.erase(MAX_SUBJECT_STRING_LEN,m_pref_CustomInvitation_Subject.length());
if (m_pref_CustomInvitation_Text.length() > MAX_INVITATION_TEXT_LEN)
m_pref_CustomInvitation_Text.erase(MAX_INVITATION_TEXT_LEN,m_pref_CustomInvitation_Text.length());
ConvertC2HTMLInvitation();
}
void vncProperties::SaveUserPrefs(HKEY appkey)
{
SaveInt(appkey, "ConnectionMode", GetConnectionMode());
// general prefs
SaveInt(appkey, "UseDynGate", m_pref_General_UseDynGate);
SaveString(appkey, "UserIdentity", m_pref_General_Identity);
SaveInt(appkey, "ConnectionLogging", m_pref_General_ConnectionLogging);
// remotecontrol prefs
SaveInt(appkey, "RemoteControlQuality", m_pref_Remote_Quality);
SaveInt(appkey, "RemoteControlCompression", m_pref_Remote_Compression);
SaveInt(appkey, "RemoteControlColors", m_pref_Remote_Colors);
SaveInt(appkey, "RemoteControlServerScale", m_pref_Remote_ServerScale);
SaveInt(appkey, "RemoteControlViewOnly", m_pref_Remote_ViewOnly);
SaveInt(appkey, "RemoteControlWallpaper", m_pref_Remote_Wallpaper);
SaveInt(appkey, "RemoteControlDisableInput", m_pref_Remote_DisableInput);
SaveInt(appkey, "RemoteControlBlackScreen", m_pref_Remote_BlackScreen);
SaveInt(appkey, "RemoteControlScaling", m_pref_Remote_Scaling);
SaveInt(appkey, "RemoteControlAutoscaling", m_pref_Remote_Autoscaling);
SaveInt(appkey, "RemoteControlScaleBy", m_pref_Remote_ScaleBy);
SaveInt(appkey, "RemoteControlShowRemoteCursor", m_pref_Remote_ShowRemoteCursor);
// presentation prefs
SaveInt(appkey, "PresentationQuality", m_pref_Presentation_Quality);
SaveInt(appkey, "PresentationCompression", m_pref_Presentation_Compression);
SaveInt(appkey, "PresentationColors", m_pref_Presentation_Colors);
SaveInt(appkey, "PresentationServerScale", m_pref_Presentation_ServerScale);
SaveInt(appkey, "PresentationSingleWindow", m_pref_Presentation_SingleWindow);
SaveString(appkey, "PresentationSWName", m_pref_Presentation_WindowNamed);
SaveString(appkey, "InvitationSubject", (char*)m_pref_CustomInvitation_Subject.c_str());
SaveString(appkey, "InvitationText", (char*)m_pref_CustomInvitation_Text.c_str());
}
// apply the cached preferences to the server
void vncProperties::ApplyPrefs()
{
m_server->SetIdentity(m_pref_General_Identity);
m_server->SetLogging(m_pref_General_Logging);
m_server->SetConnectionLogging(m_pref_General_ConnectionLogging);
// Remotecontrol settings are copied to VNCviewerApp32 in VNCviewerApp32::UpdateOptions()
// Presentation settings are read and applied in vncClientControl::Init()
// Security settings
m_server->SetLoopbackOnly(!m_pref_Security_VNC_Compat);
m_server->SockConnect(m_pref_Security_AllowIncoming);
m_server->BlankMonitorEnabled(m_pref_Security_AllowDisableInput);
m_server->EnableRemoteInputs(m_pref_Security_AllowInput);
m_server->EnableFileTransfer(m_pref_Security_EnableFileTransfer);
m_server->SetLockSettings(m_pref_Security_LockSettings);
m_server->SetConnectPriority(m_pref_Security_Multiple);
m_server->SingleWindow(m_pref_Security_SingleWindow);
m_server->SetSingleWindowName(m_pref_Security_ShareWindowNamed);
// Host settings
m_server->SetServerMode(m_pref_Host_Autostart > 0);
m_server->SetAutostartSetting(m_pref_Host_Autostart);
if(m_pref_Host_Autostart > 0)
{
m_server->SetPassword(m_pref_Host_Passwd);
CroGateway::Instance()->HostMode(true);
}
// General settings
m_server->SetUseDynGate(m_pref_General_UseDynGate);
if (m_pref_General_UseDynGate)
SessionDialog::EnableDynGate();
else
SessionDialog::DisableDynGate();
SessionDialog::UpdatePassword();
}
void vncProperties::SaveString(HKEY key,LPCSTR valname, TCHAR *buffer)
{
if(buffer!=NULL)
{
RegSetValueEx(key,valname,0,REG_SZ,(BYTE*)buffer,strlen(buffer));
}
}
void vncProperties::SaveInt(HKEY key, LPCSTR valname, LONG val)
{
RegSetValueEx(key, valname, 0, REG_DWORD, (LPBYTE) &val, sizeof(val));
}
void vncProperties::SavePassword(HKEY key, char *buffer)
{
RegSetValueEx(key, "Password", 0, REG_BINARY, (LPBYTE) buffer, MAXPWLEN);
}
void vncProperties::Save()
{
HKEY hkey;
DWORD dw;
char username[255];
if(isNoSave)
return;
// try to write machine settings to HKEY_LOCAL_MACHINE
if (RegCreateKeyEx(HKEY_LOCAL_MACHINE,
TV_REGISTRY_KEY,
0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
{
vnclog.Print(LL_INTINFO, VNCLOG("Saving machine prefs to HKEY_LOCAL_MACHINE"));
SaveMachinePrefs(hkey);
RegCloseKey(hkey);
m_Properties_Location = HKEY_LOCAL_MACHINE;
}
// if this fails write it to HKEY_CURRENT_USER
else if (RegCreateKeyEx(HKEY_CURRENT_USER,
TV_REGISTRY_KEY,
0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
{
vnclog.Print(LL_INTINFO, VNCLOG("Saving machine prefs to HKEY_CURRENT_USER"));
SaveMachinePrefs(hkey);
RegCloseKey(hkey);
m_Properties_Location = HKEY_CURRENT_USER;
}
else
{
vnclog.Print(LL_INTERR, VNCLOG("vncProperties::Save() cannot open registry for machine prefs"));
m_Properties_Location = 0;
return;
}
vncService::BeginImpersonation();
// only write user settings if we are running in user mode or as a service with impersonation
if (vncService::CurrentUser((char *)&username, sizeof(username)) && strlen(username) != 0)
{
// Try to get the per-user key
if (RegCreateKeyEx(HKEY_CURRENT_USER,
TV_REGISTRY_KEY,
0, REG_NONE, REG_OPTION_NON_VOLATILE,
KEY_WRITE | KEY_READ, NULL, &hkey, &dw) == ERROR_SUCCESS)
{
vnclog.Print(LL_INTINFO, VNCLOG("Saving user prefs for user %s"), username);
SaveUserPrefs(hkey);
RegCloseKey(hkey);
}
else
{
vnclog.Print(LL_INTERR, VNCLOG("vncProperties::Save() failed to open registry for user prefs"));
}
}
else
{
vnclog.Print(LL_INTINFO, VNCLOG("Saving user prefs: no user logged on"));
}
vncService::EndImpersonation();
}
#include <pshpack1.h> // turn packing of structures on
typedef struct DLGTEMPLATEEX
{
WORD dlgVer;
WORD signature;
DWORD helpID;
DWORD exStyle;
DWORD style;
WORD cDlgItems;
short x;
short y;
short cx;
short cy;
} DLGTEMPLATEEX, *LPDLGTEMPLATEEX;
#include <poppack.h> // turn packing of structures off again
LRESULT CALLBACK PropertyPageWndProc(
HWND hwnd,
UINT message,
UINT wParam,
LONG lParam)
{
// get the previous window procedure so we can still call it
WNDPROC OldComboProc = (WNDPROC)GetWindowLong(hwnd, GWL_USERDATA);
switch(message)
{
case WM_ERASEBKGND:
return EraseBkgnd(hwnd, wParam);
case WM_CTLCOLORBTN:
return CtlColorBtn(wParam);
case WM_CTLCOLORSTATIC:
return CtlColorStatic(hwnd, wParam, lParam);
}
// preserve original window's functionality
return CallWindowProc(OldComboProc, hwnd, message, wParam, lParam);
}
int CALLBACK RemoveContextHelpProc(HWND hwnd, UINT message, LPARAM lParam)
{
switch (message)
{
case PSCB_PRECREATE:
// Remove the DS_CONTEXTHELP style from the
// dialog box template
if (((LPDLGTEMPLATEEX)lParam)->signature ==
0xFFFF)
{
((LPDLGTEMPLATEEX)lParam)->style
&= ~DS_CONTEXTHELP;
}
else {
((LPDLGTEMPLATE)lParam)->style
&= ~DS_CONTEXTHELP;
}
return TRUE;
/*case PSCB_INITIALIZED:
InitScaling();
RECT winRect;
GetWindowRect(hwnd,&winRect);
winRect.bottom *= scaleY;
winRect.right *= scaleX;
//SetWindowPos(hwnd,0,-1,-1,winRect.right,winRect.bottom,SWP_NOREPOSITION);
//AdjustWindowRect(
//SCALEX
return TRUE;
*/
}
return TRUE;
}
int vncProperties::ShowPropertiesDialog(int startPage)
{
PROPSHEETPAGE psp[6];
PROPSHEETHEADER psh;
int iPage = 0;
ZeroMemory(&psp,sizeof(psp));
psp[iPage].dwSize = sizeof(PROPSHEETPAGE);
psp[iPage].dwFlags = PSP_USETITLE;
psp[iPage].hInstance = hAppInstance;
psp[iPage].pszTemplate = MAKEINTRESOURCE(IDD_PROPERTIES_GENERAL);
psp[iPage].pszIcon = NULL;
psp[iPage].pfnDlgProc = GeneralProc;
psp[iPage].pszTitle = sz_IDS_PROPERTIES_BASIC_CAPTION;
psp[iPage].lParam = 0;
iPage++;
psp[iPage].dwSize = sizeof(PROPSHEETPAGE);
psp[iPage].dwFlags = PSP_USETITLE;
psp[iPage].hInstance = hAppInstance;
psp[iPage].pszTemplate = MAKEINTRESOURCE(IDD_PROPERTIES_REMOTECONTROL);
psp[iPage].pszIcon = NULL;
psp[iPage].pfnDlgProc = RemoteProc;
psp[iPage].pszTitle = sz_IDS_PROPERTIES_REMOTE_CAPTION;
psp[iPage].lParam = 0;
iPage++;
psp[iPage].dwSize = sizeof(PROPSHEETPAGE);
psp[iPage].dwFlags = PSP_USETITLE;
psp[iPage].hInstance = hAppInstance;
psp[iPage].pszTemplate = MAKEINTRESOURCE(IDD_PROPERTIES_PRESENTATION);
psp[iPage].pszIcon = NULL;
psp[iPage].pfnDlgProc = PresentationProc;
psp[iPage].pszTitle = sz_IDS_PROPERTIES_PRESENTATION_CAPTION;
psp[iPage].lParam = 0;
iPage++;
psp[iPage].dwSize = sizeof(PROPSHEETPAGE);
psp[iPage].dwFlags = PSP_USETITLE;
psp[iPage].hInstance = hAppInstance;
psp[iPage].pszTemplate = MAKEINTRESOURCE(IDD_PROPERTIES_CUSTOMINVITATION);
psp[iPage].pszIcon = NULL;
psp[iPage].pfnDlgProc = InviteProc;
psp[iPage].pszTitle = sz_IDS_PROPERTIES_INVITATION_CAPTION;
psp[iPage].lParam = 0;
iPage++;
psp[iPage].dwSize = sizeof(PROPSHEETPAGE);
psp[iPage].dwFlags = PSP_USETITLE;
psp[iPage].hInstance = hAppInstance;
psp[iPage].pszTemplate = MAKEINTRESOURCE(IDD_PROPERTIES_SECURITY);
psp[iPage].pszIcon = NULL;
psp[iPage].pfnDlgProc = SecurityProc;
psp[iPage].pszTitle = sz_IDS_PROPERTIES_SECURITY_CAPTION;
psp[iPage].lParam = 0;
iPage++;
psp[iPage].dwSize = sizeof(PROPSHEETPAGE);
psp[iPage].dwFlags = PSP_USETITLE;
psp[iPage].hInstance = hAppInstance;
psp[iPage].pszTemplate = MAKEINTRESOURCE(IDD_PROPERTIES_HOST);
psp[iPage].pszIcon = NULL;
psp[iPage].pfnDlgProc = HostProc;
psp[iPage].pszTitle = sz_IDS_PROPERTIES_HOST_CAPTION;
psp[iPage].lParam = 0;
ZeroMemory(&psh,sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
/*
The flag PSH_NOCONTEXTHELP needs comctl32.dll (v5.81) that is only supported by Windows 2000 or higher.
This flag leads to a too early exiting Option dialog on unsupported functions.
So I created accordinly to
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/propsheet/propsheet.asp
a callback function that hides the help button. This workaround is compatible to newer versions.
@cw
*/
psh.dwFlags = PSH_PROPSHEETPAGE | PSH_USECALLBACK/*|PSH_NOCONTEXTHELP*/;
psh.hwndParent = SessionDialog::Hwnd();
psh.hInstance = hAppInstance;
psh.pszIcon = NULL;
psh.pszCaption = (LPSTR) sz_IDS_PROPERTIES_CAPTION;
psh.pfnCallback = RemoveContextHelpProc;
psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
psh.ppsp = (LPCPROPSHEETPAGE) &psp;
if(isNoSave || (m_pref_Security_AdminOnly && !isAdmin))
psh.nPages = 4;
else
psh.nPages = 6;
if(startPage>=psh.nPages)
psh.nStartPage=psh.nPages-1;
else
psh.nStartPage=startPage;
int result = PropertySheet(&psh);
int err = GetLastError();
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/propsheet/functions/propertysheet.asp
if(result > 0)
{
ApplyPrefs();
Save();
}
else
if (result < 0)
vnclog.Print(LL_INTERR,VNCLOG("Option dialog did not start"));
return result;
}
BOOL vncProperties::NotifyProc(HWND hwnd, UINT code, LONG (vncProperties::*verifyFunc)(HWND), LONG (vncProperties::*applyFunc)(HWND))
{
switch (code)
{
case PSN_SETACTIVE:
SetTimer(hwnd, 1, 200, NULL);
return 0;
case PSN_KILLACTIVE:
KillTimer(hwnd, 1);
if(verifyFunc)
{
SetWindowLong(hwnd, DWL_MSGRESULT, (vncProperties::singleton->*verifyFunc)(hwnd));
return TRUE;
}
else
return FALSE;
case PSN_APPLY:
SetWindowLong(hwnd, DWL_MSGRESULT, (vncProperties::singleton->*applyFunc)(hwnd));
return TRUE;
case PSN_RESET:
case PSN_QUERYCANCEL:
KillTimer(hwnd, 1);
return FALSE;
}
return 0;
}
void vncProperties::TimerProc(HWND hwnd, int idc)
{
POINT p;
GetCursorPos(&p);
HWND control = WindowFromPoint(p);
HWND helptext = GetDlgItem(hwnd, idc);
char *newtext = vncProperties::singleton->helptexts[control];
char oldtext[512];
GetWindowText(helptext, oldtext, 512);
if(newtext && strncmp(newtext, oldtext, 512))
SetWindowText(helptext, newtext);
else if(!newtext && oldtext[0]!='\0')
SetWindowText(helptext, "");
SetTimer(hwnd, 1, 200, NULL);
}
BOOL APIENTRY vncProperties::GeneralProc(
HWND hwnd,
UINT message,
UINT wParam,
LONG lParam)
{
switch (message)
{
case WM_INITDIALOG:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -