Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenhardprof.c
Go to the documentation of this file.
00001 /* 00002 * PROJECT: ReactOS System Control Panel Applet 00003 * LICENSE: GPL - See COPYING in the top level directory 00004 * FILE: dll/cpl/sysdm/hardprof.c 00005 * PURPOSE: Modify hardware profiles 00006 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com> 00007 * 00008 */ 00009 00010 #include "precomp.h" 00011 #include <debug.h> 00012 00013 typedef struct _PROFILE 00014 { 00015 WCHAR szFriendlyName[256]; 00016 } PROFILE, *PPROFILE; 00017 00018 typedef struct _PROFILEDATA 00019 { 00020 DWORD dwProfileCount; 00021 PPROFILE pProfiles; 00022 } PROFILEDATA, *PPROFILEDATA; 00023 00024 00025 static 00026 INT_PTR 00027 CALLBACK 00028 CopyProfileDlgProc(HWND hwndDlg, 00029 UINT uMsg, 00030 WPARAM wParam, 00031 LPARAM lParam) 00032 { 00033 UNREFERENCED_PARAMETER(lParam); 00034 UNREFERENCED_PARAMETER(wParam); 00035 UNREFERENCED_PARAMETER(hwndDlg); 00036 00037 switch (uMsg) 00038 { 00039 case WM_COMMAND: 00040 if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) 00041 { 00042 EndDialog(hwndDlg, 00043 LOWORD(wParam)); 00044 return TRUE; 00045 } 00046 break; 00047 } 00048 return FALSE; 00049 } 00050 00051 00052 static 00053 INT_PTR 00054 CALLBACK 00055 RenameProfileDlgProc(HWND hwndDlg, 00056 UINT uMsg, 00057 WPARAM wParam, 00058 LPARAM lParam) 00059 { 00060 UNREFERENCED_PARAMETER(lParam); 00061 UNREFERENCED_PARAMETER(wParam); 00062 UNREFERENCED_PARAMETER(hwndDlg); 00063 00064 switch (uMsg) 00065 { 00066 case WM_COMMAND: 00067 if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL)) 00068 { 00069 EndDialog(hwndDlg, 00070 LOWORD(wParam)); 00071 return TRUE; 00072 } 00073 break; 00074 } 00075 return FALSE; 00076 } 00077 00078 00079 static 00080 DWORD 00081 GetUserWaitInterval(VOID) 00082 { 00083 DWORD dwWaitInterval = 30; 00084 DWORD dwSize; 00085 HKEY hKey; 00086 00087 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00088 L"System\\CurrentControlSet\\Control\\IDConfigDB", 00089 0, 00090 KEY_QUERY_VALUE, 00091 &hKey)) 00092 return dwWaitInterval; 00093 00094 dwSize = sizeof(DWORD); 00095 RegQueryValueExW(hKey, 00096 L"UserWaitInterval", 00097 NULL, 00098 NULL, 00099 (LPBYTE)&dwWaitInterval, 00100 &dwSize); 00101 00102 RegCloseKey(hKey); 00103 00104 return dwWaitInterval; 00105 } 00106 00107 00108 static 00109 VOID 00110 SetUserWaitInterval(DWORD dwWaitInterval) 00111 { 00112 HKEY hKey; 00113 00114 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00115 L"System\\CurrentControlSet\\Control\\IDConfigDB", 00116 0, 00117 KEY_SET_VALUE, 00118 &hKey)) 00119 return; 00120 00121 RegSetValueExW(hKey, 00122 L"UserWaitInterval", 00123 0, 00124 REG_DWORD, 00125 (LPBYTE)&dwWaitInterval, 00126 sizeof(DWORD)); 00127 00128 RegCloseKey(hKey); 00129 } 00130 00131 00132 static 00133 BOOL 00134 GetProfileCount(LPDWORD lpProfileCount) 00135 { 00136 HKEY hKey; 00137 LONG lError; 00138 00139 *lpProfileCount = 0; 00140 00141 lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00142 L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles", 00143 0, 00144 KEY_READ, 00145 &hKey); 00146 if (lError != ERROR_SUCCESS) 00147 return FALSE; 00148 00149 lError = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, lpProfileCount, 00150 NULL, NULL, NULL, NULL, NULL, NULL, NULL); 00151 00152 RegCloseKey(hKey); 00153 00154 if (lError != ERROR_SUCCESS) 00155 return FALSE; 00156 00157 return TRUE; 00158 } 00159 00160 00161 static 00162 VOID 00163 GetProfile(HWND hwndDlg, HKEY hKey, LPWSTR lpName, PPROFILE pProfile) 00164 { 00165 HKEY hProfileKey; 00166 DWORD dwSize; 00167 LONG lError; 00168 00169 lError = RegOpenKeyExW(hKey, 00170 lpName, 00171 0, 00172 KEY_READ, 00173 &hProfileKey); 00174 if (lError != ERROR_SUCCESS) 00175 return; 00176 00177 dwSize = 256 * sizeof(WCHAR); 00178 lError = RegQueryValueExW(hProfileKey, 00179 L"FriendlyName", 00180 NULL, 00181 NULL, 00182 (LPBYTE)pProfile->szFriendlyName, 00183 &dwSize); 00184 if (lError == ERROR_SUCCESS) 00185 { 00186 DPRINT1("Profile: %S\n", pProfile->szFriendlyName); 00187 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_ADDSTRING, 0, (LPARAM)pProfile->szFriendlyName); 00188 } 00189 00190 RegCloseKey(hProfileKey); 00191 } 00192 00193 00194 static 00195 BOOL 00196 GetProfiles(HWND hwndDlg) 00197 { 00198 PPROFILEDATA pProfileData; 00199 WCHAR szName[8]; 00200 DWORD dwNameLength; 00201 DWORD dwIndex = 0; 00202 HKEY hKey; 00203 LONG lError; 00204 00205 pProfileData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROFILEDATA)); 00206 if (pProfileData == NULL) 00207 return FALSE; 00208 00209 if (!GetProfileCount(&pProfileData->dwProfileCount)) 00210 { 00211 HeapFree(GetProcessHeap(), 0, pProfileData); 00212 return FALSE; 00213 } 00214 00215 pProfileData->pProfiles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 00216 pProfileData->dwProfileCount * sizeof(PROFILE)); 00217 if (pProfileData->pProfiles == NULL) 00218 { 00219 HeapFree(GetProcessHeap(), 0, pProfileData); 00220 return FALSE; 00221 } 00222 00223 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pProfileData); 00224 00225 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, 00226 L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles", 00227 0, 00228 KEY_READ, 00229 &hKey) != ERROR_SUCCESS) 00230 return FALSE; 00231 00232 for (dwIndex = 0; dwIndex < pProfileData->dwProfileCount; dwIndex++) 00233 { 00234 dwNameLength = 8; 00235 lError = RegEnumKeyExW(hKey, 00236 dwIndex, 00237 szName, 00238 &dwNameLength, 00239 NULL, 00240 NULL, 00241 NULL, 00242 NULL); 00243 if (lError != ERROR_SUCCESS) 00244 break; 00245 00246 DPRINT("Profile name: %S\n", szName); 00247 00248 GetProfile(hwndDlg, hKey, szName, &pProfileData->pProfiles[dwIndex]); 00249 } 00250 00251 RegCloseKey(hKey); 00252 00253 return TRUE; 00254 } 00255 00256 00257 static 00258 BOOL 00259 OnInitDialog(HWND hwndDlg) 00260 { 00261 DWORD dwWaitInterval; 00262 00263 DPRINT("OnInitDialog()\n"); 00264 00265 SendMessage(GetDlgItem(hwndDlg, IDC_HRDPROFUP), 00266 BM_SETIMAGE,(WPARAM)IMAGE_ICON, 00267 (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_UP))); 00268 SendMessage(GetDlgItem(hwndDlg, IDC_HRDPROFDWN), 00269 BM_SETIMAGE,(WPARAM)IMAGE_ICON, 00270 (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_DOWN))); 00271 00272 if (!GetProfiles(hwndDlg)) 00273 return FALSE; 00274 00275 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG((SHORT)500, 0)); 00276 00277 dwWaitInterval = GetUserWaitInterval(); 00278 if (dwWaitInterval == (DWORD)-1) 00279 { 00280 CheckDlgButton(hwndDlg, IDC_HRDPROFWAIT, BST_CHECKED); 00281 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETPOS, 0, 30); 00282 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), FALSE); 00283 } 00284 else 00285 { 00286 CheckDlgButton(hwndDlg, IDC_HRDPROFSELECT, BST_CHECKED); 00287 SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETPOS, 0, dwWaitInterval); 00288 } 00289 00290 return TRUE; 00291 } 00292 00293 00294 static 00295 VOID 00296 OnOk(HWND hwndDlg) 00297 { 00298 DWORD dwWaitInterval; 00299 00300 if (IsDlgButtonChecked(hwndDlg, IDC_HRDPROFWAIT) == BST_CHECKED) 00301 { 00302 dwWaitInterval = (DWORD)-1; 00303 } 00304 else 00305 { 00306 dwWaitInterval = LOWORD(SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_GETPOS, 0, 0)); 00307 } 00308 00309 SetUserWaitInterval(dwWaitInterval); 00310 } 00311 00312 00313 /* Property page dialog callback */ 00314 INT_PTR 00315 CALLBACK 00316 HardProfDlgProc(HWND hwndDlg, 00317 UINT uMsg, 00318 WPARAM wParam, 00319 LPARAM lParam) 00320 { 00321 PPROFILEDATA pProfileData; 00322 00323 UNREFERENCED_PARAMETER(lParam); 00324 UNREFERENCED_PARAMETER(wParam); 00325 UNREFERENCED_PARAMETER(hwndDlg); 00326 00327 pProfileData = (PPROFILEDATA)GetWindowLongPtr(hwndDlg, DWLP_USER); 00328 00329 switch (uMsg) 00330 { 00331 case WM_INITDIALOG: 00332 return OnInitDialog(hwndDlg); 00333 00334 case WM_DESTROY: 00335 if (pProfileData != NULL) 00336 { 00337 if (pProfileData->pProfiles != NULL) 00338 HeapFree(GetProcessHeap(), 0, pProfileData->pProfiles); 00339 HeapFree(GetProcessHeap(), 0, pProfileData); 00340 } 00341 break; 00342 00343 case WM_COMMAND: 00344 switch (LOWORD(wParam)) 00345 { 00346 case IDC_HRDPROFCOPY: 00347 DialogBox(hApplet, 00348 MAKEINTRESOURCE(IDD_COPYPROFILE), 00349 hwndDlg, 00350 (DLGPROC)CopyProfileDlgProc); 00351 break; 00352 00353 case IDC_HRDPROFRENAME: 00354 DialogBox(hApplet, 00355 MAKEINTRESOURCE(IDD_RENAMEPROFILE), 00356 hwndDlg, 00357 (DLGPROC)RenameProfileDlgProc); 00358 break; 00359 00360 case IDC_HRDPROFWAIT: 00361 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), FALSE); 00362 return TRUE; 00363 00364 case IDC_HRDPROFSELECT: 00365 EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), TRUE); 00366 return TRUE; 00367 00368 case IDOK: 00369 OnOk(hwndDlg); 00370 00371 case IDCANCEL: 00372 EndDialog(hwndDlg, 00373 LOWORD(wParam)); 00374 return TRUE; 00375 } 00376 break; 00377 } 00378 00379 return FALSE; 00380 } Generated on Wed May 23 2012 04:19:05 for ReactOS by
1.7.6.1
|