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

📄 vncoptions.cpp

📁 realvnc是一个非常流行的远程控制程序
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        m_logToFile = true;      }    } else if ( SwitchMatch(args[j], _T("config") )) {      if (++j == i) {        ArgError(_T("No config file specified"));        continue;      }      // The GetPrivateProfile* stuff seems not to like some relative paths      _fullpath(m_configFilename, args[j], _MAX_PATH);      if (_access(m_configFilename, 04)) {        ArgError(_T("Can't open specified config file for reading."));        PostQuitMessage(1);        continue;      } else {        Load(m_configFilename);        m_configSpecified = true;      }    } else if ( SwitchMatch(args[j], _T("register") )) {      Register();      PostQuitMessage(0);    } else {      TCHAR phost[256];      if (!ParseDisplay(args[j], phost, 255, &m_port)) {        ShowUsage(_T("Invalid VNC server specified."));        PostQuitMessage(1);      } else {        _tcscpy(m_host, phost);        m_connectionSpecified = true;      }    }  }       	  if (m_scale_num != 1 || m_scale_den != 1) 			    m_scaling = true;	// reduce scaling factors by greatest common denominator  if (m_scaling) {    FixScaling();  }  // 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("autoDetect", autoDetect, 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("scale_num",			m_scale_num,		fname);  saveInt("scale_den",			m_scale_den,		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;  autoDetect = readInt("autoDetect", autoDetect, 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_scale_num =			readInt("scale_num",		m_scale_num,	fname);  m_scale_den =			readInt("scale_den",		m_scale_den,	fname);}// Record the path to the VNC viewer and the type// of the .vnc files in the registryvoid 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 {    log.Print(0, "Failed to register .vnc extension\n");  }  char filename[_MAX_PATH];  if (GetModuleFileName(NULL, filename, _MAX_PATH) == 0) {    log.Print(0, "Error getting vncviewer filename\n");    return;  }  log.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);  }}void VNCOptions::ShowUsage(LPTSTR info) {  TCHAR msg[1024];  TCHAR *tmpinf = _T("");  if (info != NULL)     tmpinf = info;  _stprintf(msg, #ifdef UNDER_CE            _T("%s\n\rUsage includes:\n\r")            _T("vncviewer [/8bit] [/swapmouse] [/shared] [/belldeiconify] \n\r")            _T(" [/hpc | /palm] [/slow] [server:display] \n\r")            _T("For full details see documentation."),#else            _T("%s\n\rUsage includes:\n\r"               "  vncviewer [/8bit] [/swapmouse] [/shared] [/belldeiconify] \n\r"               "      [/listen [vnc-port]] [/fullscreen] [/viewonly] [/emulate3] \n\r"               "      [/scale a/b] [/config configfile] [server:display]\n\r"               "For full details see documentation."), #endif            tmpinf);  MessageBox(NULL,  msg, _T("VNC error"), MB_OK | MB_ICONSTOP | MB_TOPMOST);}// The dialog box allows you to change the session-specific parametersint VNCOptions::DoDialog(bool running){  m_running = running;  return DialogBoxParam(pApp->m_instance, DIALOG_MAKEINTRESOURCE(IDD_OPTIONDIALOG),                         NULL, (DLGPROC) OptDlgProc, (LONG) this);}BOOL CALLBACK VNCOptions::OptDlgProc(  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);      _this = (VNCOptions *) lParam;      // Initialise the controls      HWND had = GetDlgItem(hwnd, IDC_AUTODETECT);      SendMessage(had, BM_SETCHECK, _this->autoDetect, 0);      for (int i = rfbEncodingRaw; i <= LASTENCODING; i++) {        HWND hPref = GetDlgItem(hwnd, IDC_RAWRADIO + (i-rfbEncodingRaw));        SendMessage(hPref, BM_SETCHECK,                     (i== _this->m_PreferredEncoding), 0);        EnableWindow(hPref, _this->m_UseEnc[i] && !_this->autoDetect);      }			      HWND hCopyRect = GetDlgItem(hwnd, ID_SESSION_SET_CRECT);      SendMessage(hCopyRect, BM_SETCHECK, _this->m_UseEnc[rfbEncodingCopyRect], 0);      EnableWindow(hCopyRect, !_this->autoDetect);			      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);      EnableWindow(h8bit, !_this->autoDetect);			      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);      HWND hScaling = GetDlgItem(hwnd, IDC_SCALING);      SendMessage(hScaling, BM_SETCHECK, _this->m_scaling, 0);      SetDlgItemInt( hwnd, IDC_SCALE_NUM, _this->m_scale_num, FALSE);      SetDlgItemInt( hwnd, IDC_SCALE_DEN, _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      CentreWindow(hwnd);			      return TRUE;    }  case WM_COMMAND:    switch (LOWORD(wParam)) {    case IDOK:      {        HWND had = GetDlgItem(hwnd, IDC_AUTODETECT);        _this->autoDetect =          (SendMessage(had, BM_GETCHECK, 0, 0) == BST_CHECKED);        for (int i = rfbEncodingRaw; i <= LASTENCODING; i++) {          HWND hPref = GetDlgItem(hwnd, IDC_RAWRADIO+i-rfbEncodingRaw);          if (SendMessage(hPref, BM_GETCHECK, 0, 0) == BST_CHECKED)            _this->m_PreferredEncoding = i;        }				        HWND hCopyRect = GetDlgItem(hwnd, ID_SESSION_SET_CRECT);        _this->m_UseEnc[rfbEncodingCopyRect] =          (SendMessage(hCopyRect, BM_GETCHECK, 0, 0) == BST_CHECKED);				        HWND hSwap = GetDlgItem(hwnd, ID_SESSION_SWAPMOUSE);        _this->m_SwapMouse =          (SendMessage(hSwap, BM_GETCHECK, 0, 0) == BST_CHECKED);				        HWND hDeiconify = GetDlgItem(hwnd, IDC_BELLDEICONIFY);        _this->m_DeiconifyOnBell =          (SendMessage(hDeiconify, BM_GETCHECK, 0, 0) == BST_CHECKED);#ifndef UNDER_CE				        HWND hDisableClip = GetDlgItem(hwnd, IDC_DISABLECLIPBOARD);        _this->m_DisableClipboard =          (SendMessage(hDisableClip, BM_GETCHECK, 0, 0) == BST_CHECKED);#endif        HWND h8bit = GetDlgItem(hwnd, IDC_8BITCHECK);        _this->m_Use8Bit =          (SendMessage(h8bit, BM_GETCHECK, 0, 0) == BST_CHECKED);				        HWND hShared = GetDlgItem(hwnd, IDC_SHARED);        _this->m_Shared =          (SendMessage(hShared, BM_GETCHECK, 0, 0) == BST_CHECKED);				        HWND hViewOnly = GetDlgItem(hwnd, IDC_VIEWONLY);        _this->m_ViewOnly =           (SendMessage(hViewOnly, BM_GETCHECK, 0, 0) == BST_CHECKED);        HWND hScaling = GetDlgItem(hwnd, IDC_SCALING);        _this->m_scaling =           (SendMessage(hScaling, BM_GETCHECK, 0, 0) == BST_CHECKED);        if (_this->m_scaling) {          _this->m_scale_num = GetDlgItemInt( hwnd, IDC_SCALE_NUM, NULL, TRUE);          _this->m_scale_den = GetDlgItemInt( hwnd, IDC_SCALE_DEN, NULL, TRUE);          _this->FixScaling();          if (_this->m_scale_num == 1 && _this->m_scale_den == 1)            _this->m_scaling = false;        } else {          _this->m_scale_num = 1;          _this->m_scale_den = 1;        }#ifndef UNDER_CE        HWND hFullScreen = GetDlgItem(hwnd, IDC_FULLSCREEN);        _this->m_FullScreen =           (SendMessage(hFullScreen, BM_GETCHECK, 0, 0) == BST_CHECKED);        HWND hEmulate = GetDlgItem(hwnd, IDC_EMULATECHECK);        _this->m_Emul3Buttons =          (SendMessage(hEmulate, BM_GETCHECK, 0, 0) == BST_CHECKED);#endif        EndDialog(hwnd, TRUE);				        return TRUE;      }    case IDCANCEL:      EndDialog(hwnd, FALSE);      return TRUE;    case IDC_AUTODETECT:      bool ad = IsDlgButtonChecked(hwnd, IDC_AUTODETECT);      for (int i = rfbEncodingRaw; i <= LASTENCODING; i++) {        HWND hPref = GetDlgItem(hwnd, IDC_RAWRADIO + (i-rfbEncodingRaw));        EnableWindow(hPref, _this->m_UseEnc[i] && !ad);      }			      HWND hCopyRect = GetDlgItem(hwnd, ID_SESSION_SET_CRECT);      EnableWindow(hCopyRect, !ad);			      HWND h8bit = GetDlgItem(hwnd, IDC_8BITCHECK);      EnableWindow(h8bit, !ad);      return TRUE;    }    break;  case WM_DESTROY:    EndDialog(hwnd, FALSE);    return TRUE;  }  return 0;}

⌨️ 快捷键说明

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