Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

127 lines
3.3 KiB

  1. #include "properties.h"
  2. #include "util.h"
  3. static const TCHAR c_szSharedAccessClientKeyPathDownlevel[] = TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ICSClient");
  4. static const TCHAR c_szShowIcon[] = TEXT("ShowIcon");
  5. CPropertiesDialog::CPropertiesDialog(IInternetGateway* pInternetGateway)
  6. {
  7. m_hIcon = NULL;
  8. m_pInternetGateway = pInternetGateway;
  9. m_pInternetGateway->AddRef();
  10. }
  11. CPropertiesDialog::~CPropertiesDialog()
  12. {
  13. m_pInternetGateway->Release();
  14. }
  15. LRESULT CPropertiesDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  16. {
  17. HRESULT hr = S_OK;
  18. // load the little icon, this can not be done in the rc file, it stretches the icon
  19. int cx = GetSystemMetrics(SM_CXSMICON);
  20. int cy = GetSystemMetrics(SM_CYSMICON);
  21. m_hIcon = reinterpret_cast<HICON>(LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(IDI_GATEWAY), IMAGE_ICON, cx, cy, LR_DEFAULTCOLOR));
  22. if(NULL != m_hIcon)
  23. {
  24. SendDlgItemMessage(IDC_PROPERTIES_ADAPTERICON, STM_SETICON, reinterpret_cast<WPARAM>(m_hIcon), 0);
  25. }
  26. // set the text with the connection name
  27. LPTSTR pszConnectionName;
  28. hr = GetConnectionName(m_pInternetGateway, &pszConnectionName);
  29. if(SUCCEEDED(hr))
  30. {
  31. SetDlgItemText(IDC_PROPERTIES_ADAPTERNAME, pszConnectionName);
  32. LocalFree(pszConnectionName);
  33. }
  34. // check the show icon checkbox
  35. if(SUCCEEDED(ShouldShowIcon()))
  36. {
  37. CheckDlgButton(IDC_PROPERTIES_SHOWICON, BST_CHECKED);
  38. }
  39. return 0;
  40. }
  41. LRESULT CPropertiesDialog::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  42. {
  43. if(NULL != m_hIcon)
  44. {
  45. DestroyIcon(m_hIcon);
  46. }
  47. return 0;
  48. }
  49. LRESULT CPropertiesDialog::OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  50. {
  51. NMHDR* pNotifyHeader = reinterpret_cast<NMHDR*>(lParam);
  52. if(PSN_APPLY == pNotifyHeader->code)
  53. {
  54. SetShowIcon(BST_CHECKED == IsDlgButtonChecked(IDC_PROPERTIES_SHOWICON));
  55. }
  56. return 0;
  57. }
  58. HRESULT CPropertiesDialog::ShouldShowIcon(void)
  59. {
  60. HRESULT hr = S_OK;
  61. HKEY hKey;
  62. if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, c_szSharedAccessClientKeyPathDownlevel, NULL, KEY_QUERY_VALUE, &hKey))
  63. {
  64. DWORD dwType;
  65. DWORD dwValue;
  66. DWORD dwSize = sizeof(dwValue);
  67. if(ERROR_SUCCESS == RegQueryValueEx(hKey, c_szShowIcon, NULL, &dwType, reinterpret_cast<LPBYTE>(&dwValue), &dwSize))
  68. {
  69. if(REG_DWORD == dwType && 0 == dwValue)
  70. {
  71. hr = E_FAIL;
  72. }
  73. }
  74. RegCloseKey(hKey);
  75. }
  76. return hr;
  77. }
  78. HRESULT CPropertiesDialog::SetShowIcon(BOOL bShowIcon)
  79. {
  80. HRESULT hr = S_OK;
  81. HKEY hKey;
  82. if(ERROR_SUCCESS == RegCreateKeyEx(HKEY_LOCAL_MACHINE, c_szSharedAccessClientKeyPathDownlevel, NULL, TEXT(""), 0, KEY_SET_VALUE, NULL, &hKey, NULL))
  83. {
  84. DWORD dwValue = bShowIcon;
  85. if(ERROR_SUCCESS == RegSetValueEx(hKey, c_szShowIcon, NULL, REG_DWORD, reinterpret_cast<LPBYTE>(&dwValue), sizeof(dwValue)))
  86. {
  87. hr = S_OK;
  88. }
  89. else
  90. {
  91. hr = E_FAIL;
  92. }
  93. RegCloseKey(hKey);
  94. }
  95. else
  96. {
  97. hr = E_FAIL;
  98. }
  99. return hr;
  100. }