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>
14 typedef struct _PROFILE
16 WCHAR szFriendlyName
[256];
19 typedef struct _PROFILEDATA
23 } PROFILEDATA
, *PPROFILEDATA
;
29 CopyProfileDlgProc(HWND hwndDlg
,
34 UNREFERENCED_PARAMETER(lParam
);
35 UNREFERENCED_PARAMETER(wParam
);
36 UNREFERENCED_PARAMETER(hwndDlg
);
41 if ((LOWORD(wParam
) == IDOK
) || (LOWORD(wParam
) == IDCANCEL
))
56 RenameProfileDlgProc(HWND hwndDlg
,
61 UNREFERENCED_PARAMETER(lParam
);
62 UNREFERENCED_PARAMETER(wParam
);
63 UNREFERENCED_PARAMETER(hwndDlg
);
68 if ((LOWORD(wParam
) == IDOK
) || (LOWORD(wParam
) == IDCANCEL
))
82 GetUserWaitInterval(VOID
)
84 DWORD dwWaitInterval
= 30;
88 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
89 L
"System\\CurrentControlSet\\Control\\IDConfigDB",
93 return dwWaitInterval
;
95 dwSize
= sizeof(DWORD
);
96 RegQueryValueExW(hKey
,
100 (LPBYTE
)&dwWaitInterval
,
105 return dwWaitInterval
;
111 SetUserWaitInterval(DWORD dwWaitInterval
)
115 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
116 L
"System\\CurrentControlSet\\Control\\IDConfigDB",
126 (LPBYTE
)&dwWaitInterval
,
135 GetProfileCount(LPDWORD lpProfileCount
)
142 lError
= RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
143 L
"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles",
147 if (lError
!= ERROR_SUCCESS
)
150 lError
= RegQueryInfoKeyW(hKey
, NULL
, NULL
, NULL
, lpProfileCount
,
151 NULL
, NULL
, NULL
, NULL
, NULL
, NULL
, NULL
);
155 if (lError
!= ERROR_SUCCESS
)
164 GetProfile(HWND hwndDlg
, HKEY hKey
, LPWSTR lpName
, PPROFILE pProfile
)
170 lError
= RegOpenKeyExW(hKey
,
175 if (lError
!= ERROR_SUCCESS
)
178 dwSize
= 256 * sizeof(WCHAR
);
179 lError
= RegQueryValueExW(hProfileKey
,
183 (LPBYTE
)pProfile
->szFriendlyName
,
185 if (lError
== ERROR_SUCCESS
)
187 DPRINT1("Profile: %S\n", pProfile
->szFriendlyName
);
188 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFLSTBOX
, LB_ADDSTRING
, 0, (LPARAM
)pProfile
->szFriendlyName
);
191 RegCloseKey(hProfileKey
);
197 GetProfiles(HWND hwndDlg
)
199 PPROFILEDATA pProfileData
;
206 pProfileData
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(PROFILEDATA
));
207 if (pProfileData
== NULL
)
210 if (!GetProfileCount(&pProfileData
->dwProfileCount
))
212 HeapFree(GetProcessHeap(), 0, pProfileData
);
216 pProfileData
->pProfiles
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
217 pProfileData
->dwProfileCount
* sizeof(PROFILE
));
218 if (pProfileData
->pProfiles
== NULL
)
220 HeapFree(GetProcessHeap(), 0, pProfileData
);
224 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pProfileData
);
226 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
,
227 L
"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles",
230 &hKey
) != ERROR_SUCCESS
)
233 for (dwIndex
= 0; dwIndex
< pProfileData
->dwProfileCount
; dwIndex
++)
236 lError
= RegEnumKeyExW(hKey
,
244 if (lError
!= ERROR_SUCCESS
)
247 DPRINT("Profile name: %S\n", szName
);
249 GetProfile(hwndDlg
, hKey
, szName
, &pProfileData
->pProfiles
[dwIndex
]);
260 OnInitDialog(HWND hwndDlg
)
262 DWORD dwWaitInterval
;
264 DPRINT("OnInitDialog()\n");
266 SendMessage(GetDlgItem(hwndDlg
, IDC_HRDPROFUP
),
267 BM_SETIMAGE
,(WPARAM
)IMAGE_ICON
,
268 (LPARAM
)(HANDLE
)LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_UP
)));
269 SendMessage(GetDlgItem(hwndDlg
, IDC_HRDPROFDWN
),
270 BM_SETIMAGE
,(WPARAM
)IMAGE_ICON
,
271 (LPARAM
)(HANDLE
)LoadIcon(hApplet
, MAKEINTRESOURCE(IDI_DOWN
)));
273 if (!GetProfiles(hwndDlg
))
276 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_SETRANGE
, (WPARAM
)0, (LPARAM
)MAKELONG((SHORT
)500, 0));
278 dwWaitInterval
= GetUserWaitInterval();
279 if (dwWaitInterval
== (DWORD
)-1)
281 CheckDlgButton(hwndDlg
, IDC_HRDPROFWAIT
, BST_CHECKED
);
282 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_SETPOS
, 0, 30);
283 EnableWindow(GetDlgItem(hwndDlg
, IDC_HRDPROFEDIT
), FALSE
);
287 CheckDlgButton(hwndDlg
, IDC_HRDPROFSELECT
, BST_CHECKED
);
288 SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_SETPOS
, 0, dwWaitInterval
);
299 DWORD dwWaitInterval
;
301 if (IsDlgButtonChecked(hwndDlg
, IDC_HRDPROFWAIT
) == BST_CHECKED
)
303 dwWaitInterval
= (DWORD
)-1;
307 dwWaitInterval
= LOWORD(SendDlgItemMessageW(hwndDlg
, IDC_HRDPROFUPDWN
, UDM_GETPOS
, 0, 0));
310 SetUserWaitInterval(dwWaitInterval
);
314 /* Property page dialog callback */
317 HardProfDlgProc(HWND hwndDlg
,
322 PPROFILEDATA pProfileData
;
324 UNREFERENCED_PARAMETER(lParam
);
325 UNREFERENCED_PARAMETER(wParam
);
326 UNREFERENCED_PARAMETER(hwndDlg
);
328 pProfileData
= (PPROFILEDATA
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
333 return OnInitDialog(hwndDlg
);
336 if (pProfileData
!= NULL
)
338 if (pProfileData
->pProfiles
!= NULL
)
339 HeapFree(GetProcessHeap(), 0, pProfileData
->pProfiles
);
340 HeapFree(GetProcessHeap(), 0, pProfileData
);
345 switch (LOWORD(wParam
))
347 case IDC_HRDPROFCOPY
:
349 MAKEINTRESOURCE(IDD_COPYPROFILE
),
351 (DLGPROC
)CopyProfileDlgProc
);
354 case IDC_HRDPROFRENAME
:
356 MAKEINTRESOURCE(IDD_RENAMEPROFILE
),
358 (DLGPROC
)RenameProfileDlgProc
);
361 case IDC_HRDPROFWAIT
:
362 EnableWindow(GetDlgItem(hwndDlg
, IDC_HRDPROFEDIT
), FALSE
);
365 case IDC_HRDPROFSELECT
:
366 EnableWindow(GetDlgItem(hwndDlg
, IDC_HRDPROFEDIT
), TRUE
);