1 /* -*- Mode: C; tab-width: 4 -*- 2 * 3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include "FourthPage.h" 19 #include "resource.h" 20 21 #include "ConfigPropertySheet.h" 22 #include "SharedSecret.h" 23 24 #include <WinServices.h> 25 26 #define MAX_KEY_LENGTH 255 27 28 29 IMPLEMENT_DYNCREATE(CFourthPage, CPropertyPage) 30 31 32 //--------------------------------------------------------------------------------------------------------------------------- 33 // CFourthPage::CFourthPage 34 //--------------------------------------------------------------------------------------------------------------------------- 35 36 CFourthPage::CFourthPage() 37 : 38 CPropertyPage(CFourthPage::IDD) 39 { 40 //{{AFX_DATA_INIT(CFourthPage) 41 //}}AFX_DATA_INIT 42 } 43 44 45 //--------------------------------------------------------------------------------------------------------------------------- 46 // CFourthPage::~CFourthPage 47 //--------------------------------------------------------------------------------------------------------------------------- 48 49 CFourthPage::~CFourthPage() 50 { 51 } 52 53 54 //--------------------------------------------------------------------------------------------------------------------------- 55 // CFourthPage::DoDataExchange 56 //--------------------------------------------------------------------------------------------------------------------------- 57 58 void CFourthPage::DoDataExchange(CDataExchange* pDX) 59 { 60 CPropertyPage::DoDataExchange(pDX); 61 //{{AFX_DATA_MAP(CFourthPage) 62 //}}AFX_DATA_MAP 63 DDX_Control(pDX, IDC_POWER_MANAGEMENT, m_checkBox); 64 } 65 66 BEGIN_MESSAGE_MAP(CFourthPage, CPropertyPage) 67 //{{AFX_MSG_MAP(CFourthPage) 68 //}}AFX_MSG_MAP 69 70 ON_BN_CLICKED(IDC_POWER_MANAGEMENT, &CFourthPage::OnBnClickedPowerManagement) 71 72 END_MESSAGE_MAP() 73 74 75 //--------------------------------------------------------------------------------------------------------------------------- 76 // CFourthPage::SetModified 77 //--------------------------------------------------------------------------------------------------------------------------- 78 79 void CFourthPage::SetModified( BOOL bChanged ) 80 { 81 m_modified = bChanged; 82 83 CPropertyPage::SetModified( bChanged ); 84 } 85 86 87 //--------------------------------------------------------------------------------------------------------------------------- 88 // CFourthPage::OnSetActive 89 //--------------------------------------------------------------------------------------------------------------------------- 90 91 BOOL 92 CFourthPage::OnSetActive() 93 { 94 CConfigPropertySheet * psheet; 95 HKEY key = NULL; 96 DWORD dwSize; 97 DWORD enabled; 98 DWORD err; 99 BOOL b = CPropertyPage::OnSetActive(); 100 101 psheet = reinterpret_cast<CConfigPropertySheet*>(GetParent()); 102 require_quiet( psheet, exit ); 103 104 m_checkBox.SetCheck( 0 ); 105 106 // Now populate the browse domain box 107 108 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Power Management", 0, 109 NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE|KEY_WOW64_32KEY, NULL, &key, NULL ); 110 require_noerr( err, exit ); 111 112 dwSize = sizeof( DWORD ); 113 err = RegQueryValueEx( key, L"Enabled", NULL, NULL, (LPBYTE) &enabled, &dwSize ); 114 require_noerr( err, exit ); 115 116 m_checkBox.SetCheck( enabled ); 117 118 exit: 119 120 if ( key ) 121 { 122 RegCloseKey( key ); 123 } 124 125 return b; 126 } 127 128 129 //--------------------------------------------------------------------------------------------------------------------------- 130 // CFourthPage::OnOK 131 //--------------------------------------------------------------------------------------------------------------------------- 132 133 void 134 CFourthPage::OnOK() 135 { 136 if ( m_modified ) 137 { 138 Commit(); 139 } 140 } 141 142 143 144 //--------------------------------------------------------------------------------------------------------------------------- 145 // CFourthPage::Commit 146 //--------------------------------------------------------------------------------------------------------------------------- 147 148 void 149 CFourthPage::Commit() 150 { 151 HKEY key = NULL; 152 DWORD enabled; 153 DWORD err; 154 155 err = RegCreateKeyEx( HKEY_LOCAL_MACHINE, kServiceParametersNode L"\\Power Management", 0, 156 NULL, REG_OPTION_NON_VOLATILE, KEY_READ|KEY_WRITE|KEY_WOW64_32KEY, NULL, &key, NULL ); 157 require_noerr( err, exit ); 158 159 enabled = m_checkBox.GetCheck(); 160 err = RegSetValueEx( key, L"Enabled", NULL, REG_DWORD, (LPBYTE) &enabled, sizeof( enabled ) ); 161 require_noerr( err, exit ); 162 163 exit: 164 165 if ( key ) 166 { 167 RegCloseKey( key ); 168 } 169 } 170 171 172 //--------------------------------------------------------------------------------------------------------------------------- 173 // CFourthPage::OnBnClickedRemoveBrowseDomain 174 //--------------------------------------------------------------------------------------------------------------------------- 175 176 177 178 void CFourthPage::OnBnClickedPowerManagement() 179 180 { 181 182 char buf[ 256 ]; 183 184 185 186 sprintf( buf, "check box: %d", m_checkBox.GetCheck() ); 187 188 OutputDebugStringA( buf ); 189 190 // TODO: Add your control notification handler code here 191 192 193 194 SetModified( TRUE ); 195 196 } 197 198