pgsvedef.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 4k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. #include "pch.hxx" // pch
  2. #pragma hdrstop
  3. #include "resource.h"
  4. #include "pgSveDef.h"
  5. // JMC: This is taken from access.cpl
  6. /***********************************************************************/
  7. // CopyKey( hKey, hKeyDst, name )
  8. //     create the destination key
  9. //     for each value
  10. //         CopyValue
  11. //     for each subkey
  12. //         CopyKey
  13. DWORD CopyKey( HKEY hkeySrc, HKEY hkeyDst, LPSTR szKey )
  14. {
  15.     HKEY hkeyOld, hkeyNew;
  16.     char szValue[128];
  17.     BYTE szData[128];
  18.     char szBuffer[128];
  19.     DWORD iStatus;
  20.     UINT nValue, nKey;
  21.     DWORD iValueLen, iDataLen;
  22. DWORD dwType;
  23.     iStatus = RegOpenKeyA( hkeySrc, szKey, &hkeyOld );
  24.     if( iStatus != ERROR_SUCCESS )
  25.         return iStatus;
  26.     iStatus = RegOpenKeyA( hkeyDst, szKey, &hkeyNew );
  27.     if( iStatus != ERROR_SUCCESS )
  28.     {
  29.         iStatus = RegCreateKeyA( hkeyDst, szKey, &hkeyNew );
  30.         if( iStatus != ERROR_SUCCESS )
  31.         {
  32.             RegCloseKey( hkeyOld );
  33.             return iStatus;
  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.         RegCloseKey( hkeyOld );
  58.         RegCloseKey( hkeyNew );
  59.         return iStatus;
  60.     }
  61.     //*********** copy the subtrees ************** //
  62.     for( nKey = 0;
  63.          ERROR_SUCCESS == (iStatus = RegEnumKeyA(hkeyOld,nKey,szBuffer,sizeof(szBuffer)));
  64.          nKey ++ )
  65.      {
  66.          iStatus = CopyKey( hkeyOld, hkeyNew, szBuffer );
  67.          if( iStatus != ERROR_NO_MORE_ITEMS && iStatus != ERROR_SUCCESS )
  68.             {
  69.                 RegCloseKey( hkeyOld );
  70.                 RegCloseKey( hkeyNew );
  71.                 return iStatus;
  72.             }
  73.      }
  74.     RegCloseKey( hkeyOld );
  75.     RegCloseKey( hkeyNew );
  76.     if( iStatus == ERROR_NO_MORE_ITEMS )
  77.         return ERROR_SUCCESS;
  78.     else
  79.         return iStatus;
  80. }
  81. DWORD SaveLookToDefaultUser( void )
  82. {
  83.     DWORD iStatus;
  84.     HKEY hkeyDst;
  85.     iStatus  = RegOpenKeyA( HKEY_USERS, ".DEFAULT", &hkeyDst );
  86.     if( iStatus != ERROR_SUCCESS )
  87.         return iStatus;
  88.     iStatus = CopyKey( HKEY_CURRENT_USER, hkeyDst, "Control Panel\Desktop");
  89.     iStatus = CopyKey( HKEY_CURRENT_USER, hkeyDst, "Control Panel\Colors");
  90.     RegCloseKey( hkeyDst );
  91.     return iStatus;
  92. }
  93. DWORD SaveAccessibilityToDefaultUser( void )
  94. {
  95.     DWORD iStatus;
  96.     HKEY hkeyDst;
  97.     iStatus  = RegOpenKeyA( HKEY_USERS, ".DEFAULT", &hkeyDst );
  98.     if( iStatus != ERROR_SUCCESS )
  99.         return iStatus;
  100.     iStatus = CopyKey( HKEY_CURRENT_USER, hkeyDst, "Control Panel\Accessibility");
  101.     RegCloseKey( hkeyDst );
  102.     return iStatus;
  103. }
  104. CSaveForDefaultUserPg::CSaveForDefaultUserPg( 
  105.     LPPROPSHEETPAGE ppsp
  106. ) : WizardPage(ppsp, IDS_WIZSAVEASDEFAULTTITLE, IDS_WIZSAVEASDEFAULTSUBTITLE)
  107. {
  108. m_dwPageId = IDD_WIZWORKSTATIONDEFAULT;
  109.     ppsp->pszTemplate = MAKEINTRESOURCE(m_dwPageId);
  110. }
  111. CSaveForDefaultUserPg::~CSaveForDefaultUserPg(
  112.     VOID
  113.     )
  114. {
  115. }
  116. LRESULT CSaveForDefaultUserPg::OnPSN_WizNext(HWND hwnd, INT idCtl, LPPSHNOTIFY pnmh)
  117. {
  118. if(Button_GetCheck(GetDlgItem(m_hwnd, IDC_CHECKSAVESETTINGTODEFAULT)))
  119. {
  120. SaveAccessibilityToDefaultUser();
  121. SaveLookToDefaultUser();
  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. }