1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2004 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include "ServicesPage.h"
21 #include "ControlPanelExe.h"
22 #include "ConfigPropertySheet.h"
24 #include <WinServices.h>
26 #define MAX_KEY_LENGTH 255
29 IMPLEMENT_DYNCREATE(CServicesPage
, CPropertyPage
)
32 //---------------------------------------------------------------------------------------------------------------------------
33 // CServicesPage::CServicesPage
34 //---------------------------------------------------------------------------------------------------------------------------
36 CServicesPage::CServicesPage()
38 CPropertyPage(CServicesPage::IDD
)
40 //{{AFX_DATA_INIT(CServicesPage)
45 //---------------------------------------------------------------------------------------------------------------------------
46 // CServicesPage::~CServicesPage
47 //---------------------------------------------------------------------------------------------------------------------------
49 CServicesPage::~CServicesPage()
54 //---------------------------------------------------------------------------------------------------------------------------
55 // CServicesPage::DoDataExchange
56 //---------------------------------------------------------------------------------------------------------------------------
58 void CServicesPage::DoDataExchange(CDataExchange
* pDX
)
60 CPropertyPage::DoDataExchange(pDX
);
61 //{{AFX_DATA_MAP(CServicesPage)
63 DDX_Control(pDX
, IDC_ADVERTISE_SMB
, m_SMBCheckBox
);
64 DDX_Control(pDX
, IDC_POWER_MANAGEMENT
, m_powerManagementCheckBox
);
67 BEGIN_MESSAGE_MAP(CServicesPage
, CPropertyPage
)
68 //{{AFX_MSG_MAP(CServicesPage)
71 ON_BN_CLICKED(IDC_ADVERTISE_SMB
, &CServicesPage::OnBnClickedAdvertiseSMB
)
72 ON_BN_CLICKED(IDC_POWER_MANAGEMENT
, &CServicesPage::OnBnClickedPowerManagement
)
77 //---------------------------------------------------------------------------------------------------------------------------
78 // CServicesPage::SetModified
79 //---------------------------------------------------------------------------------------------------------------------------
81 void CServicesPage::SetModified( BOOL bChanged
)
83 m_modified
= bChanged
;
85 CPropertyPage::SetModified( bChanged
);
89 //---------------------------------------------------------------------------------------------------------------------------
90 // CServicesPage::OnSetActive
91 //---------------------------------------------------------------------------------------------------------------------------
94 CServicesPage::OnSetActive()
96 CConfigPropertySheet
* psheet
;
101 BOOL b
= CPropertyPage::OnSetActive();
103 psheet
= reinterpret_cast<CConfigPropertySheet
*>(GetParent());
104 require_quiet( psheet
, exit
);
106 m_SMBCheckBox
.SetCheck( 0 );
108 // Now populate the browse domain box
110 err
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\Services\\SMB", 0,
111 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &key
, NULL
);
112 require_noerr( err
, exit
);
114 dwSize
= sizeof( DWORD
);
115 err
= RegQueryValueEx( key
, L
"Advertise", NULL
, NULL
, (LPBYTE
) &enabled
, &dwSize
);
116 require_noerr( err
, exit
);
118 m_SMBCheckBox
.SetCheck( enabled
);
123 m_powerManagementCheckBox
.SetCheck( 0 );
125 // Now populate the browse domain box
127 err
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\Power Management", 0,
128 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &key
, NULL
);
129 require_noerr( err
, exit
);
131 dwSize
= sizeof( DWORD
);
132 err
= RegQueryValueEx( key
, L
"Enabled", NULL
, NULL
, (LPBYTE
) &enabled
, &dwSize
);
133 require_noerr( err
, exit
);
135 m_powerManagementCheckBox
.SetCheck( enabled
);
148 //---------------------------------------------------------------------------------------------------------------------------
149 // CServicesPage::OnOK
150 //---------------------------------------------------------------------------------------------------------------------------
153 CServicesPage::OnOK()
163 //---------------------------------------------------------------------------------------------------------------------------
164 // CServicesPage::Commit
165 //---------------------------------------------------------------------------------------------------------------------------
168 CServicesPage::Commit()
174 err
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\Services\\SMB", 0,
175 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &key
, NULL
);
176 require_noerr( err
, exit
);
178 enabled
= m_SMBCheckBox
.GetCheck();
179 err
= RegSetValueEx( key
, L
"Advertise", NULL
, REG_DWORD
, (LPBYTE
) &enabled
, sizeof( enabled
) );
180 require_noerr( err
, exit
);
185 err
= RegCreateKeyEx( HKEY_LOCAL_MACHINE
, kServiceParametersNode L
"\\Power Management", 0,
186 NULL
, REG_OPTION_NON_VOLATILE
, KEY_READ
|KEY_WRITE
, NULL
, &key
, NULL
);
187 require_noerr( err
, exit
);
189 enabled
= m_powerManagementCheckBox
.GetCheck();
190 err
= RegSetValueEx( key
, L
"Enabled", NULL
, REG_DWORD
, (LPBYTE
) &enabled
, sizeof( enabled
) );
191 require_noerr( err
, exit
);
202 //---------------------------------------------------------------------------------------------------------------------------
203 // CServicesPage::OnBnClickedAdvertiseSMB
204 //---------------------------------------------------------------------------------------------------------------------------
206 void CServicesPage::OnBnClickedAdvertiseSMB()
212 //---------------------------------------------------------------------------------------------------------------------------
213 // CServicesPage::OnBnClickedPowerManagement
214 //---------------------------------------------------------------------------------------------------------------------------
216 void CServicesPage::OnBnClickedPowerManagement()
220 if ( m_powerManagementCheckBox
.GetCheck() )
222 CPowerManagementWarning
dlg( GetParent() );
229 // CPowerManagementWarning dialog
231 IMPLEMENT_DYNAMIC(CPowerManagementWarning
, CDialog
)
232 CPowerManagementWarning::CPowerManagementWarning(CWnd
* pParent
/*=NULL*/)
233 : CDialog(CPowerManagementWarning::IDD
, pParent
)
237 CPowerManagementWarning::~CPowerManagementWarning()
241 void CPowerManagementWarning::DoDataExchange(CDataExchange
* pDX
)
243 CDialog::DoDataExchange(pDX
);
244 DDX_Control(pDX
, IDC_ENERGY_SAVER
, m_energySaverIcon
);
249 CPowerManagementWarning::OnInitDialog()
251 BOOL b
= CDialog::OnInitDialog();
253 const HICON hIcon
= ( HICON
) ::LoadImage( GetNonLocalizedResources(), MAKEINTRESOURCE( IDI_ENERGY_SAVER
), IMAGE_ICON
, 0, 0, 0);
257 m_energySaverIcon
.SetIcon( hIcon
);
265 CPowerManagementWarning::OnOK()
271 BEGIN_MESSAGE_MAP(CPowerManagementWarning
, CDialog
)