Source code of Windows XP (NT5)
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.

174 lines
4.5 KiB

  1. //Copyright (c) 1997-2000 Microsoft Corporation
  2. #include "pch.hxx" // pch
  3. #pragma hdrstop
  4. #include "resource.h"
  5. #include "pgSveDef.h"
  6. // JMC: This is taken from access.cpl
  7. /***********************************************************************/
  8. // CopyKey( hKey, hKeyDst, name )
  9. // create the destination key
  10. // for each value
  11. // CopyValue
  12. // for each subkey
  13. // CopyKey
  14. DWORD CopyKey( HKEY hkeySrc, HKEY hkeyDst, LPSTR szKey )
  15. {
  16. HKEY hkeyOld = NULL, hkeyNew = NULL;
  17. char szValue[128];
  18. BYTE szData[128];
  19. char szBuffer[128];
  20. DWORD iStatus;
  21. UINT nValue, nKey;
  22. DWORD iValueLen, iDataLen;
  23. DWORD dwType;
  24. iStatus = RegOpenKeyA( hkeySrc, szKey, &hkeyOld );
  25. if( iStatus != ERROR_SUCCESS)
  26. goto exit;
  27. iStatus = RegOpenKeyA( hkeyDst, szKey, &hkeyNew );
  28. if( iStatus != ERROR_SUCCESS )
  29. {
  30. iStatus = RegCreateKeyA( hkeyDst, szKey, &hkeyNew );
  31. if( iStatus != ERROR_SUCCESS )
  32. {
  33. goto exit;
  34. }
  35. }
  36. //*********** copy the values **************** //
  37. for( nValue = 0, iValueLen=sizeof szValue, iDataLen=sizeof szValue;
  38. ERROR_SUCCESS == (iStatus = RegEnumValueA(hkeyOld,
  39. nValue,
  40. szValue,
  41. &iValueLen,
  42. NULL, // reserved
  43. &dwType, // don't need type
  44. szData,
  45. &iDataLen ) );
  46. nValue ++, iValueLen=sizeof szValue, iDataLen=sizeof szValue )
  47. {
  48. iStatus = RegSetValueExA( hkeyNew,
  49. szValue,
  50. 0, // reserved
  51. dwType,
  52. szData,
  53. iDataLen);
  54. }
  55. if( iStatus != ERROR_NO_MORE_ITEMS )
  56. {
  57. goto exit;
  58. }
  59. //*********** copy the subtrees ************** //
  60. for( nKey = 0;
  61. ERROR_SUCCESS == (iStatus = RegEnumKeyA(hkeyOld,nKey,szBuffer,sizeof(szBuffer)));
  62. nKey ++ )
  63. {
  64. iStatus = CopyKey( hkeyOld, hkeyNew, szBuffer );
  65. if( iStatus != ERROR_NO_MORE_ITEMS && iStatus != ERROR_SUCCESS )
  66. {
  67. goto exit;
  68. }
  69. }
  70. if( iStatus == ERROR_NO_MORE_ITEMS )
  71. iStatus = ERROR_SUCCESS;
  72. exit:
  73. if (hkeyOld)
  74. RegCloseKey(hkeyOld);
  75. if (hkeyNew)
  76. RegCloseKey(hkeyNew);
  77. return iStatus;
  78. }
  79. DWORD SaveLookToDefaultUser( void )
  80. {
  81. DWORD iStatus;
  82. HKEY hkeyDst;
  83. iStatus = RegOpenKeyA( HKEY_USERS, ".DEFAULT", &hkeyDst );
  84. if( iStatus != ERROR_SUCCESS )
  85. return iStatus;
  86. iStatus = CopyKey( HKEY_CURRENT_USER, hkeyDst, "Control Panel\\Desktop");
  87. iStatus = CopyKey( HKEY_CURRENT_USER, hkeyDst, "Control Panel\\Colors");
  88. RegCloseKey( hkeyDst );
  89. return iStatus;
  90. }
  91. DWORD SaveAccessibilityToDefaultUser( void )
  92. {
  93. DWORD iStatus;
  94. HKEY hkeyDst;
  95. iStatus = RegOpenKeyA( HKEY_USERS, ".DEFAULT", &hkeyDst );
  96. if( iStatus != ERROR_SUCCESS )
  97. return iStatus;
  98. iStatus = CopyKey( HKEY_CURRENT_USER, hkeyDst, "Control Panel\\Accessibility");
  99. RegCloseKey( hkeyDst );
  100. return iStatus;
  101. }
  102. CSaveForDefaultUserPg::CSaveForDefaultUserPg(
  103. LPPROPSHEETPAGE ppsp
  104. ) : WizardPage(ppsp, IDS_WIZSAVEASDEFAULTTITLE, IDS_WIZSAVEASDEFAULTSUBTITLE)
  105. {
  106. m_dwPageId = IDD_WIZWORKSTATIONDEFAULT;
  107. ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  108. }
  109. CSaveForDefaultUserPg::~CSaveForDefaultUserPg(
  110. VOID
  111. )
  112. {
  113. }
  114. LRESULT CSaveForDefaultUserPg::OnPSN_WizNext(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  115. {
  116. if(Button_GetCheck(GetDlgItem(m_hwnd, IDC_CHECKSAVESETTINGTODEFAULT)))
  117. {
  118. SaveAccessibilityToDefaultUser();
  119. // JMC Check for admin privleges for both callse
  120. if(ERROR_SUCCESS != SaveLookToDefaultUser())
  121. StringTableMessageBox(m_hwnd, IDS_WIZERRORNEEDADMINTEXT, IDS_WIZERRORNEEDADMINTITLE, MB_OK);
  122. }
  123. return WizardPage::OnPSN_WizNext(hwnd, idCtl, pnmh);
  124. }
  125. LRESULT
  126. CSaveForDefaultUserPg::OnCommand(
  127. HWND hwnd,
  128. WPARAM wParam,
  129. LPARAM lParam
  130. )
  131. {
  132. LRESULT lResult = 1;
  133. WORD wNotifyCode = HIWORD(wParam);
  134. WORD wCtlID = LOWORD(wParam);
  135. HWND hwndCtl = (HWND)lParam;
  136. return lResult;
  137. }
  138. LRESULT
  139. CSaveForDefaultUserPg::OnInitDialog(
  140. HWND hwnd,
  141. WPARAM wParam,
  142. LPARAM lParam
  143. )
  144. {
  145. Button_SetCheck(GetDlgItem(m_hwnd, IDC_RADIO2), TRUE);
  146. return 1;
  147. }