2 * PROJECT: ReactOS System Control Panel Applet
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/sysdm/hardprof.c
5 * PURPOSE: Modify hardware profiles
6 * COPYRIGHT: Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
13 typedef struct _PROFILE
15 WCHAR szFriendlyName
[256];
18 typedef struct _PROFILEDATA
22 } PROFILEDATA
, *PPROFILEDATA
;
28 CopyProfileDlgProc(HWND hwndDlg
,
33 UNREFERENCED_PARAMETER(lParam
);
34 UNREFERENCED_PARAMETER(wParam
);
35 UNREFERENCED_PARAMETER(hwndDlg
);
40 if ((LOWORD(wParam
) == IDOK
) || (LOWORD(wParam
) == IDCANCEL
))
55 RenameProfileDlgProc(HWND hwndDlg
,
60 UNREFERENCED_PARAMETER(lParam
);
61 UNREFERENCED_PARAMETER(wParam
);
62 UNREFERENCED_PARAMETER(hwndDlg
);
67 if ((LOWORD(wParam
) == IDOK
) || (LOWORD(wParam
) == IDCANCEL
))
81 GetUserWaitInterval(VOID
)
83 DWORD dwWaitInterval
= 30;
87 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
88 L
"System\\CurrentControlSet\\Control\\IDConfigDB",
92 return dwWaitInterval
;
94 dwSize
= sizeof(DWORD
);
95 RegQueryValueExW(hKey
,
99 (LPBYTE
)&dwWaitInterval
,
104 return dwWaitInterval
;
110 SetUserWaitInterval(DWORD dwWaitInterval
)
114 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
115 L
"System\\CurrentControlSet\\Control\\IDConfigDB",
125 (LPBYTE
)&dwWaitInterval
,
134 GetProfileCount(LPDWORD lpProfileCount
)
141 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
142 L
"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles",
146 if (lError
!= ERROR_SUCCESS
)
149 lError
= RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, lpProfileCount
,
150 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
154 if (lError
!= ERROR_SUCCESS
)
163 GetProfile(HWND hwndDlg
, HKEY hKey
, LPWSTR lpName
, PPROFILE pProfile
)
169 lError
= RegOpenKeyExW(hKey
,
174 if (lError
!= ERROR_SUCCESS
)
177 dwSize
= 256 * sizeof(WCHAR
);
178 lError
= RegQueryValueExW(hProfileKey
,
182 (LPBYTE
)pProfile
->szFriendlyName
,
184 if (lError
== ERROR_SUCCESS
)
186 DPRINT1("Profile: %S\n", pProfile
->szFriendlyName
);
187 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFLSTBOX
, LB_ADDSTRING
, 0, (LPARAM
)pProfile
->szFriendlyName
);
190 RegCloseKey(hProfileKey
);
196 GetProfiles(HWND hwndDlg
)
198 PPROFILEDATA pProfileData
;
205 pProfileData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(PROFILEDATA
));
206 if (pProfileData
== NULL
)
209 if (!GetProfileCount(&pProfileData
->dwProfileCount
))
211 HeapFree(GetProcessHeap(), 0, pProfileData
);
215 pProfileData
->pProfiles
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
216 pProfileData
->dwProfileCount
* sizeof(PROFILE
));
217 if (pProfileData
->pProfiles
== NULL
)
219 HeapFree(GetProcessHeap(), 0, pProfileData
);
223 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pProfileData
);
225 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
226 L
"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles",
229 &hKey
) != ERROR_SUCCESS
)
232 for (dwIndex
= 0; dwIndex
< pProfileData
->dwProfileCount
; dwIndex
++)
235 lError
= RegEnumKeyExW(hKey
,
243 if (lError
!= ERROR_SUCCESS
)
246 DPRINT("Profile name: %S\n", szName
);
248 GetProfile(hwndDlg
, hKey
, szName
, &pProfileData
->pProfiles
[dwIndex
]);
259 OnInitDialog(HWND hwndDlg
)
261 DWORD dwWaitInterval
;
263 DPRINT("OnInitDialog()\n");
265 SendMessage(GetDlgItem(hwndDlg
, IDC_HRDPROFUP
),
266 BM_SETIMAGE
,(WPARAM
)IMAGE_ICON
,
267 (LPARAM
)(HANDLE
)LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_UP
)));
268 SendMessage(GetDlgItem(hwndDlg
, IDC_HRDPROFDWN
),
269 BM_SETIMAGE
,(WPARAM
)IMAGE_ICON
,
270 (LPARAM
)(HANDLE
)LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_DOWN
)));
272 if (!GetProfiles(hwndDlg
))
275 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_SETRANGE
, (WPARAM
)0, (LPARAM
)MAKELONG((SHORT
)500, 0));
277 dwWaitInterval
= GetUserWaitInterval();
278 if (dwWaitInterval
== (DWORD
)-1)
280 CheckDlgButton(hwndDlg
, IDC_HRDPROFWAIT
, BST_CHECKED
);
281 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_SETPOS
, 0, 30);
282 EnableWindow(GetDlgItem(hwndDlg
, IDC_HRDPROFEDIT
), FALSE
);
286 CheckDlgButton(hwndDlg
, IDC_HRDPROFSELECT
, BST_CHECKED
);
287 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_SETPOS
, 0, dwWaitInterval
);
298 DWORD dwWaitInterval
;
300 if (IsDlgButtonChecked(hwndDlg
, IDC_HRDPROFWAIT
) == BST_CHECKED
)
302 dwWaitInterval
= (DWORD
)-1;
306 dwWaitInterval
= LOWORD(SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_GETPOS
, 0, 0));
309 SetUserWaitInterval(dwWaitInterval
);
313 /* Property page dialog callback */
316 HardProfDlgProc(HWND hwndDlg
,
321 PPROFILEDATA pProfileData
;
323 UNREFERENCED_PARAMETER(lParam
);
324 UNREFERENCED_PARAMETER(wParam
);
325 UNREFERENCED_PARAMETER(hwndDlg
);
327 pProfileData
= (PPROFILEDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
332 return OnInitDialog(hwndDlg
);
335 if (pProfileData
!= NULL
)
337 if (pProfileData
->pProfiles
!= NULL
)
338 HeapFree(GetProcessHeap(), 0, pProfileData
->pProfiles
);
339 HeapFree(GetProcessHeap(), 0, pProfileData
);
344 switch (LOWORD(wParam
))
346 case IDC_HRDPROFCOPY
:
348 MAKEINTRESOURCE(IDD_COPYPROFILE
),
350 (DLGPROC
)CopyProfileDlgProc
);
353 case IDC_HRDPROFRENAME
:
355 MAKEINTRESOURCE(IDD_RENAMEPROFILE
),
357 (DLGPROC
)RenameProfileDlgProc
);
360 case IDC_HRDPROFWAIT
:
361 EnableWindow(GetDlgItem(hwndDlg
, IDC_HRDPROFEDIT
), FALSE
);
364 case IDC_HRDPROFSELECT
:
365 EnableWindow(GetDlgItem(hwndDlg
, IDC_HRDPROFEDIT
), TRUE
);