xref: /reactos/dll/cpl/sysdm/hardprof.c (revision a8e06d92)
1c2c66affSColin Finck /*
2c2c66affSColin Finck  * PROJECT:     ReactOS System Control Panel Applet
3c2c66affSColin Finck  * LICENSE:     GPL - See COPYING in the top level directory
4c2c66affSColin Finck  * FILE:        dll/cpl/sysdm/hardprof.c
5c2c66affSColin Finck  * PURPOSE:     Modify hardware profiles
6c2c66affSColin Finck  * COPYRIGHT:   Copyright 2006 Ged Murphy <gedmurphy@gmail.com>
7c2c66affSColin Finck  *
8c2c66affSColin Finck  */
9c2c66affSColin Finck 
10c2c66affSColin Finck #include "precomp.h"
11c2c66affSColin Finck 
12c2c66affSColin Finck #include <debug.h>
13c2c66affSColin Finck 
14c2c66affSColin Finck #define PROFILE_NAME_LENGTH 80
15c2c66affSColin Finck 
16c2c66affSColin Finck typedef struct _PROFILE
17c2c66affSColin Finck {
18c2c66affSColin Finck     WCHAR szFriendlyName[PROFILE_NAME_LENGTH];
19c2c66affSColin Finck     WCHAR szName[5];
20c2c66affSColin Finck     DWORD dwProfileNumber;
21c2c66affSColin Finck     DWORD dwPreferenceOrder;
22c2c66affSColin Finck } PROFILE, *PPROFILE;
23c2c66affSColin Finck 
24c2c66affSColin Finck typedef struct _PROFILEDATA
25c2c66affSColin Finck {
26c2c66affSColin Finck     DWORD dwProfileCount;
27c2c66affSColin Finck     DWORD dwLastProfile;
28c2c66affSColin Finck     DWORD dwSelectedProfile;
29c2c66affSColin Finck     DWORD dwSelectedProfileIndex;
30c2c66affSColin Finck     PPROFILE pProfiles;
31c2c66affSColin Finck } PROFILEDATA, *PPROFILEDATA;
32c2c66affSColin Finck 
33c2c66affSColin Finck typedef struct _PROFILENAMES
34c2c66affSColin Finck {
35c2c66affSColin Finck     WCHAR szSourceName[PROFILE_NAME_LENGTH];
36c2c66affSColin Finck     WCHAR szDestinationName[PROFILE_NAME_LENGTH];
37c2c66affSColin Finck     PPROFILEDATA pProfileData;
38c2c66affSColin Finck } PROFILENAMES, *PPROFILENAMES;
39c2c66affSColin Finck 
40c2c66affSColin Finck 
41c2c66affSColin Finck static
42c2c66affSColin Finck VOID
UpdateButtons(HWND hwndDlg,PPROFILEDATA pProfileData)43c2c66affSColin Finck UpdateButtons(
44c2c66affSColin Finck     HWND hwndDlg,
45c2c66affSColin Finck     PPROFILEDATA pProfileData)
46c2c66affSColin Finck {
47c2c66affSColin Finck     EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFPROP), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE);
48c2c66affSColin Finck     EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFCOPY), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE);
49c2c66affSColin Finck     EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFRENAME), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE);
50c2c66affSColin Finck     EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFDEL), (pProfileData->dwSelectedProfileIndex != (DWORD)-1) ? TRUE : FALSE);
51c2c66affSColin Finck 
52c2c66affSColin Finck     if (pProfileData->dwProfileCount < 2)
53c2c66affSColin Finck     {
54c2c66affSColin Finck         EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFUP), FALSE);
55c2c66affSColin Finck         EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFDWN), FALSE);
56c2c66affSColin Finck     }
57c2c66affSColin Finck     else
58c2c66affSColin Finck     {
59c2c66affSColin Finck         EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFUP),
60c2c66affSColin Finck                      (pProfileData->dwSelectedProfileIndex > 0) ? TRUE : FALSE);
61c2c66affSColin Finck         EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFDWN),
62c2c66affSColin Finck                      (pProfileData->dwSelectedProfileIndex < pProfileData->dwProfileCount - 1) ? TRUE : FALSE);
63c2c66affSColin Finck     }
64c2c66affSColin Finck }
65c2c66affSColin Finck 
66c2c66affSColin Finck 
67c2c66affSColin Finck static
68c2c66affSColin Finck BOOL
IsProfileNameInUse(PPROFILENAMES pProfileNames,BOOL bIgnoreCurrent)69c2c66affSColin Finck IsProfileNameInUse(
70c2c66affSColin Finck     PPROFILENAMES pProfileNames,
71c2c66affSColin Finck     BOOL bIgnoreCurrent)
72c2c66affSColin Finck {
73c2c66affSColin Finck     DWORD i;
74c2c66affSColin Finck 
75c2c66affSColin Finck     for (i = 0; i < pProfileNames->pProfileData->dwProfileCount; i++)
76c2c66affSColin Finck     {
77c2c66affSColin Finck         if (bIgnoreCurrent == TRUE && i == pProfileNames->pProfileData->dwSelectedProfileIndex)
78c2c66affSColin Finck             continue;
79c2c66affSColin Finck 
80c2c66affSColin Finck         if (wcscmp(pProfileNames->pProfileData->pProfiles[i].szFriendlyName, pProfileNames->szDestinationName) == 0)
81c2c66affSColin Finck             return TRUE;
82c2c66affSColin Finck     }
83c2c66affSColin Finck 
84c2c66affSColin Finck     return FALSE;
85c2c66affSColin Finck }
86c2c66affSColin Finck 
87c2c66affSColin Finck 
88c2c66affSColin Finck static
89c2c66affSColin Finck INT_PTR
90c2c66affSColin Finck CALLBACK
CopyProfileDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)91c2c66affSColin Finck CopyProfileDlgProc(
92c2c66affSColin Finck     HWND hwndDlg,
93c2c66affSColin Finck     UINT uMsg,
94c2c66affSColin Finck     WPARAM wParam,
95c2c66affSColin Finck     LPARAM lParam)
96c2c66affSColin Finck {
97c2c66affSColin Finck     PPROFILENAMES pProfileNames;
98c2c66affSColin Finck 
99c2c66affSColin Finck     pProfileNames = (PPROFILENAMES)GetWindowLongPtr(hwndDlg, DWLP_USER);
100c2c66affSColin Finck 
101c2c66affSColin Finck     switch (uMsg)
102c2c66affSColin Finck     {
103c2c66affSColin Finck         case WM_INITDIALOG:
104c2c66affSColin Finck             SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
105c2c66affSColin Finck             pProfileNames = (PPROFILENAMES)lParam;
106c2c66affSColin Finck 
107c2c66affSColin Finck             /* Set the old name */
108c2c66affSColin Finck             SetDlgItemText(hwndDlg, IDC_COPYPROFILEFROM, pProfileNames->szSourceName);
109c2c66affSColin Finck 
110c2c66affSColin Finck             /* Set the new name */
111c2c66affSColin Finck             SendDlgItemMessageW(hwndDlg, IDC_COPYPROFILETO, EM_SETLIMITTEXT, PROFILE_NAME_LENGTH - 1, 0);
112c2c66affSColin Finck             SetDlgItemText(hwndDlg, IDC_COPYPROFILETO, pProfileNames->szDestinationName);
113c2c66affSColin Finck             break;
114c2c66affSColin Finck 
115c2c66affSColin Finck         case WM_COMMAND:
116c2c66affSColin Finck             switch (LOWORD(wParam))
117c2c66affSColin Finck             {
118c2c66affSColin Finck                 case IDOK:
119c2c66affSColin Finck                     GetDlgItemText(hwndDlg,
120c2c66affSColin Finck                                    IDC_COPYPROFILETO,
121c2c66affSColin Finck                                    pProfileNames->szDestinationName,
122c2c66affSColin Finck                                    PROFILE_NAME_LENGTH);
123c2c66affSColin Finck                     if (IsProfileNameInUse(pProfileNames, FALSE))
124*a8e06d92SHermès Bélusca-Maïto                     {
125c2c66affSColin Finck                         ResourceMessageBox(hApplet,
126*a8e06d92SHermès Bélusca-Maïto                                            hwndDlg,
127c2c66affSColin Finck                                            MB_OK | MB_ICONERROR,
128c2c66affSColin Finck                                            IDS_HWPROFILE_WARNING,
129c2c66affSColin Finck                                            IDS_HWPROFILE_ALREADY_IN_USE);
130*a8e06d92SHermès Bélusca-Maïto                     }
131c2c66affSColin Finck                     else
132*a8e06d92SHermès Bélusca-Maïto                     {
133c2c66affSColin Finck                         EndDialog(hwndDlg, IDOK);
134*a8e06d92SHermès Bélusca-Maïto                     }
135c2c66affSColin Finck                     return TRUE;
136c2c66affSColin Finck 
137c2c66affSColin Finck                 case IDCANCEL:
138c2c66affSColin Finck                     EndDialog(hwndDlg, IDCANCEL);
139c2c66affSColin Finck                     return TRUE;
140c2c66affSColin Finck             }
141c2c66affSColin Finck             break;
142c2c66affSColin Finck     }
143c2c66affSColin Finck 
144c2c66affSColin Finck     return FALSE;
145c2c66affSColin Finck }
146c2c66affSColin Finck 
147c2c66affSColin Finck 
148c2c66affSColin Finck static
149c2c66affSColin Finck VOID
CopyHardwareProfile(HWND hwndDlg,PPROFILEDATA pProfileData)150c2c66affSColin Finck CopyHardwareProfile(
151c2c66affSColin Finck     HWND hwndDlg,
152c2c66affSColin Finck     PPROFILEDATA pProfileData)
153c2c66affSColin Finck {
154c2c66affSColin Finck     PROFILENAMES ProfileNames;
155c2c66affSColin Finck     PPROFILE pProfile, pNewProfiles, pNewProfile;
156c2c66affSColin Finck     WCHAR szBuffer[80];
157c2c66affSColin Finck 
158c2c66affSColin Finck     pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex];
159c2c66affSColin Finck 
160c2c66affSColin Finck     LoadStringW(hApplet, IDS_HWPROFILE_PROFILE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR));
161c2c66affSColin Finck 
162c2c66affSColin Finck     wcscpy(ProfileNames.szSourceName, pProfile->szFriendlyName);
163c2c66affSColin Finck     swprintf(ProfileNames.szDestinationName, L"%s %lu", szBuffer, pProfileData->dwProfileCount);
164c2c66affSColin Finck 
165c2c66affSColin Finck     ProfileNames.pProfileData = pProfileData;
166c2c66affSColin Finck 
167c2c66affSColin Finck     if (DialogBoxParam(hApplet,
168c2c66affSColin Finck                        MAKEINTRESOURCE(IDD_COPYPROFILE),
169c2c66affSColin Finck                        hwndDlg,
170bcbe0dd8SThomas Faber                        CopyProfileDlgProc,
171c2c66affSColin Finck                        (LPARAM)&ProfileNames) != IDOK)
172c2c66affSColin Finck         return;
173c2c66affSColin Finck 
174c2c66affSColin Finck     /* Apply new name only if it has been changed */
175c2c66affSColin Finck     if (wcscmp(ProfileNames.szSourceName, ProfileNames.szDestinationName) == 0)
176c2c66affSColin Finck         return;
177c2c66affSColin Finck 
178c2c66affSColin Finck     /* Allocate memory for the new profile */
179c2c66affSColin Finck     pNewProfiles = HeapReAlloc(GetProcessHeap(),
180c2c66affSColin Finck                                HEAP_ZERO_MEMORY,
181c2c66affSColin Finck                                pProfileData->pProfiles,
182c2c66affSColin Finck                                (pProfileData->dwProfileCount + 1) * sizeof(PROFILE));
183c2c66affSColin Finck     if (pNewProfiles == NULL)
184c2c66affSColin Finck     {
185c2c66affSColin Finck         DPRINT1("HeapReAlloc() failed!\n");
186c2c66affSColin Finck         return;
187c2c66affSColin Finck     }
188c2c66affSColin Finck 
189c2c66affSColin Finck     pProfileData->dwProfileCount++;
190c2c66affSColin Finck     pProfileData->pProfiles = pNewProfiles;
191c2c66affSColin Finck 
192c2c66affSColin Finck     pNewProfile = &pProfileData->pProfiles[pProfileData->dwProfileCount - 1];
193c2c66affSColin Finck 
194c2c66affSColin Finck     CopyMemory(pNewProfile, pProfile, sizeof(PROFILE));
195c2c66affSColin Finck 
196c2c66affSColin Finck     wcscpy(pNewProfile->szFriendlyName, ProfileNames.szDestinationName);
197c2c66affSColin Finck 
198c2c66affSColin Finck     pNewProfile->dwProfileNumber = ++pProfileData->dwLastProfile;
199c2c66affSColin Finck     swprintf(pNewProfile->szName, L"%04lu", pNewProfile->dwProfileNumber);
200c2c66affSColin Finck 
201c2c66affSColin Finck     pNewProfile->dwPreferenceOrder = pNewProfile->dwProfileNumber;
202c2c66affSColin Finck 
203c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_ADDSTRING, 0, (LPARAM)pNewProfile->szFriendlyName);
204c2c66affSColin Finck 
205c2c66affSColin Finck     UpdateButtons(hwndDlg, pProfileData);
206c2c66affSColin Finck }
207c2c66affSColin Finck 
208c2c66affSColin Finck 
209c2c66affSColin Finck static
210c2c66affSColin Finck INT_PTR
211c2c66affSColin Finck CALLBACK
RenameProfileDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)212c2c66affSColin Finck RenameProfileDlgProc(
213c2c66affSColin Finck     HWND hwndDlg,
214c2c66affSColin Finck     UINT uMsg,
215c2c66affSColin Finck     WPARAM wParam,
216c2c66affSColin Finck     LPARAM lParam)
217c2c66affSColin Finck {
218c2c66affSColin Finck     PPROFILENAMES pProfileNames;
219c2c66affSColin Finck 
220c2c66affSColin Finck     pProfileNames = (PPROFILENAMES)GetWindowLongPtr(hwndDlg, DWLP_USER);
221c2c66affSColin Finck 
222c2c66affSColin Finck     switch (uMsg)
223c2c66affSColin Finck     {
224c2c66affSColin Finck         case WM_INITDIALOG:
225c2c66affSColin Finck             SetWindowLongPtr(hwndDlg, DWLP_USER, lParam);
226c2c66affSColin Finck             pProfileNames = (PPROFILENAMES)lParam;
227c2c66affSColin Finck 
228c2c66affSColin Finck             /* Set the old name */
229c2c66affSColin Finck             SetDlgItemText(hwndDlg, IDC_RENPROFEDITFROM, pProfileNames->szSourceName);
230c2c66affSColin Finck 
231c2c66affSColin Finck             /* Set the new name */
232c2c66affSColin Finck             SendDlgItemMessageW(hwndDlg, IDC_RENPROFEDITTO, EM_SETLIMITTEXT, PROFILE_NAME_LENGTH - 1, 0);
233c2c66affSColin Finck             SetDlgItemText(hwndDlg, IDC_RENPROFEDITTO, pProfileNames->szDestinationName);
234c2c66affSColin Finck             break;
235c2c66affSColin Finck 
236c2c66affSColin Finck         case WM_COMMAND:
237c2c66affSColin Finck             switch (LOWORD(wParam))
238c2c66affSColin Finck             {
239c2c66affSColin Finck                 case IDOK:
240c2c66affSColin Finck                     GetDlgItemText(hwndDlg,
241c2c66affSColin Finck                                    IDC_RENPROFEDITTO,
242c2c66affSColin Finck                                    pProfileNames->szDestinationName,
243c2c66affSColin Finck                                    PROFILE_NAME_LENGTH);
244c2c66affSColin Finck                     if (IsProfileNameInUse(pProfileNames, TRUE))
245*a8e06d92SHermès Bélusca-Maïto                     {
246c2c66affSColin Finck                         ResourceMessageBox(hApplet,
247*a8e06d92SHermès Bélusca-Maïto                                            hwndDlg,
248c2c66affSColin Finck                                            MB_OK | MB_ICONERROR,
249c2c66affSColin Finck                                            IDS_HWPROFILE_WARNING,
250c2c66affSColin Finck                                            IDS_HWPROFILE_ALREADY_IN_USE);
251*a8e06d92SHermès Bélusca-Maïto                     }
252c2c66affSColin Finck                     else
253*a8e06d92SHermès Bélusca-Maïto                     {
254c2c66affSColin Finck                         EndDialog(hwndDlg, IDOK);
255*a8e06d92SHermès Bélusca-Maïto                     }
256c2c66affSColin Finck                     return TRUE;
257c2c66affSColin Finck 
258c2c66affSColin Finck                 case IDCANCEL:
259c2c66affSColin Finck                     EndDialog(hwndDlg, IDCANCEL);
260c2c66affSColin Finck                     return TRUE;
261c2c66affSColin Finck             }
262c2c66affSColin Finck             break;
263c2c66affSColin Finck     }
264c2c66affSColin Finck 
265c2c66affSColin Finck     return FALSE;
266c2c66affSColin Finck }
267c2c66affSColin Finck 
268c2c66affSColin Finck 
269c2c66affSColin Finck static
270c2c66affSColin Finck VOID
RenameHardwareProfile(HWND hwndDlg,PPROFILEDATA pProfileData)271c2c66affSColin Finck RenameHardwareProfile(
272c2c66affSColin Finck     HWND hwndDlg,
273c2c66affSColin Finck     PPROFILEDATA pProfileData)
274c2c66affSColin Finck {
275c2c66affSColin Finck     PROFILENAMES ProfileNames;
276c2c66affSColin Finck     PPROFILE pProfile;
277c2c66affSColin Finck     WCHAR szBuffer[80];
278c2c66affSColin Finck 
279c2c66affSColin Finck     pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex];
280c2c66affSColin Finck 
281c2c66affSColin Finck     LoadStringW(hApplet, IDS_HWPROFILE_PROFILE, szBuffer, sizeof(szBuffer) / sizeof(WCHAR));
282c2c66affSColin Finck 
283c2c66affSColin Finck     wcscpy(ProfileNames.szSourceName, pProfile->szFriendlyName);
284c2c66affSColin Finck     swprintf(ProfileNames.szDestinationName, L"%s %lu", szBuffer, pProfileData->dwProfileCount);
285c2c66affSColin Finck 
286c2c66affSColin Finck     ProfileNames.pProfileData = pProfileData;
287c2c66affSColin Finck 
288c2c66affSColin Finck     if (DialogBoxParam(hApplet,
289c2c66affSColin Finck                        MAKEINTRESOURCE(IDD_RENAMEPROFILE),
290c2c66affSColin Finck                        hwndDlg,
291bcbe0dd8SThomas Faber                        RenameProfileDlgProc,
292c2c66affSColin Finck                        (LPARAM)&ProfileNames) != IDOK)
293c2c66affSColin Finck         return;
294c2c66affSColin Finck 
295c2c66affSColin Finck     /* Apply new name only if it has been changed */
296c2c66affSColin Finck     if (wcscmp(pProfile->szFriendlyName, ProfileNames.szDestinationName) == 0)
297c2c66affSColin Finck         return;
298c2c66affSColin Finck 
299c2c66affSColin Finck     /* Replace the profile name in the profile list */
300c2c66affSColin Finck     wcscpy(pProfile->szFriendlyName, ProfileNames.szDestinationName);
301c2c66affSColin Finck 
302c2c66affSColin Finck     /* Replace the profile name in the listbox */
303c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, pProfileData->dwSelectedProfileIndex, 0);
304c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_INSERTSTRING, pProfileData->dwSelectedProfileIndex, (LPARAM)pProfile->szFriendlyName);
305c2c66affSColin Finck }
306c2c66affSColin Finck 
307c2c66affSColin Finck 
308c2c66affSColin Finck static
309c2c66affSColin Finck VOID
DeleteHardwareProfile(HWND hwndDlg,PPROFILEDATA pProfileData)310c2c66affSColin Finck DeleteHardwareProfile(
311c2c66affSColin Finck     HWND hwndDlg,
312c2c66affSColin Finck     PPROFILEDATA pProfileData)
313c2c66affSColin Finck {
314c2c66affSColin Finck     PPROFILE pProfiles;
315c2c66affSColin Finck     PPROFILE pProfile;
316c2c66affSColin Finck 
317c2c66affSColin Finck     pProfile = &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex];
318c2c66affSColin Finck 
319*a8e06d92SHermès Bélusca-Maïto     if (ResourceMessageBox(hApplet,
320*a8e06d92SHermès Bélusca-Maïto                            hwndDlg,
321*a8e06d92SHermès Bélusca-Maïto                            MB_YESNO | MB_ICONQUESTION,
322*a8e06d92SHermès Bélusca-Maïto                            IDS_HWPROFILE_CONFIRM_DELETE_TITLE,
323*a8e06d92SHermès Bélusca-Maïto                            IDS_HWPROFILE_CONFIRM_DELETE,
324*a8e06d92SHermès Bélusca-Maïto                            pProfile->szFriendlyName) != IDYES)
325*a8e06d92SHermès Bélusca-Maïto     {
326c2c66affSColin Finck         return;
327*a8e06d92SHermès Bélusca-Maïto     }
328c2c66affSColin Finck 
329c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, pProfileData->dwSelectedProfileIndex, 0);
330c2c66affSColin Finck 
331c2c66affSColin Finck     if (pProfileData->dwSelectedProfileIndex != pProfileData->dwProfileCount - 1)
332c2c66affSColin Finck     {
333c2c66affSColin Finck         RtlMoveMemory(&pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex],
334c2c66affSColin Finck                       &pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex + 1],
335c2c66affSColin Finck                       (pProfileData->dwProfileCount - pProfileData->dwSelectedProfileIndex - 1) * sizeof(PROFILE));
336c2c66affSColin Finck     }
337c2c66affSColin Finck     else
338c2c66affSColin Finck     {
339c2c66affSColin Finck         pProfileData->dwSelectedProfileIndex--;
340c2c66affSColin Finck     }
341c2c66affSColin Finck 
342c2c66affSColin Finck     pProfiles = HeapReAlloc(GetProcessHeap(),
343c2c66affSColin Finck                             HEAP_ZERO_MEMORY,
344c2c66affSColin Finck                             pProfileData->pProfiles,
345c2c66affSColin Finck                             (pProfileData->dwProfileCount - 1) * sizeof(PROFILE));
346c2c66affSColin Finck     if (pProfiles == NULL)
347c2c66affSColin Finck     {
348c2c66affSColin Finck         DPRINT1("HeapReAlloc() failed!\n");
349c2c66affSColin Finck         return;
350c2c66affSColin Finck     }
351c2c66affSColin Finck 
352c2c66affSColin Finck     pProfileData->dwProfileCount--;
353c2c66affSColin Finck     pProfileData->pProfiles = pProfiles;
354c2c66affSColin Finck 
355c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_SETCURSEL, pProfileData->dwSelectedProfileIndex, 0);
356c2c66affSColin Finck 
357c2c66affSColin Finck     UpdateButtons(hwndDlg, pProfileData);
358c2c66affSColin Finck }
359c2c66affSColin Finck 
360c2c66affSColin Finck 
361c2c66affSColin Finck static
362c2c66affSColin Finck VOID
MoveHardwareProfile(HWND hwndDlg,PPROFILEDATA pProfileData,BOOL bMoveUp)363c2c66affSColin Finck MoveHardwareProfile(
364c2c66affSColin Finck     HWND hwndDlg,
365c2c66affSColin Finck     PPROFILEDATA pProfileData,
366c2c66affSColin Finck     BOOL bMoveUp)
367c2c66affSColin Finck {
368c2c66affSColin Finck     PROFILE TempProfile;
369c2c66affSColin Finck     PPROFILE pSrcProfile, pDstProfile;
370c2c66affSColin Finck     DWORD dwSrcIndex, dwDstIndex;
371c2c66affSColin Finck 
372c2c66affSColin Finck     dwSrcIndex = pProfileData->dwSelectedProfileIndex;
373c2c66affSColin Finck     dwDstIndex = bMoveUp ? (dwSrcIndex - 1) : (dwSrcIndex + 1);
374c2c66affSColin Finck 
375c2c66affSColin Finck     pSrcProfile = &pProfileData->pProfiles[dwSrcIndex];
376c2c66affSColin Finck     pDstProfile = &pProfileData->pProfiles[dwDstIndex];
377c2c66affSColin Finck 
378c2c66affSColin Finck     CopyMemory(&TempProfile, pDstProfile, sizeof(PROFILE));
379c2c66affSColin Finck     CopyMemory(pDstProfile, pSrcProfile, sizeof(PROFILE));
380c2c66affSColin Finck     CopyMemory(pSrcProfile, &TempProfile, sizeof(PROFILE));
381c2c66affSColin Finck 
382c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_DELETESTRING, dwSrcIndex, 0);
383c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_INSERTSTRING, dwDstIndex, (LPARAM)pDstProfile->szFriendlyName);
384c2c66affSColin Finck 
385c2c66affSColin Finck     pProfileData->dwSelectedProfileIndex = dwDstIndex;
386c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_SETCURSEL, pProfileData->dwSelectedProfileIndex, 0);
387c2c66affSColin Finck 
388c2c66affSColin Finck     UpdateButtons(hwndDlg, pProfileData);
389c2c66affSColin Finck }
390c2c66affSColin Finck 
391c2c66affSColin Finck 
392c2c66affSColin Finck static
393c2c66affSColin Finck INT_PTR
394c2c66affSColin Finck CALLBACK
HardwareProfilePropertiesDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)395c2c66affSColin Finck HardwareProfilePropertiesDlgProc(
396c2c66affSColin Finck     HWND hwndDlg,
397c2c66affSColin Finck     UINT uMsg,
398c2c66affSColin Finck     WPARAM wParam,
399c2c66affSColin Finck     LPARAM lParam)
400c2c66affSColin Finck {
401c2c66affSColin Finck     UNREFERENCED_PARAMETER(hwndDlg);
402c2c66affSColin Finck     UNREFERENCED_PARAMETER(lParam);
403c2c66affSColin Finck     UNREFERENCED_PARAMETER(wParam);
404c2c66affSColin Finck 
405c2c66affSColin Finck     switch (uMsg)
406c2c66affSColin Finck     {
407c2c66affSColin Finck         case WM_INITDIALOG:
408c2c66affSColin Finck             return TRUE;
409c2c66affSColin Finck 
410c2c66affSColin Finck     }
411c2c66affSColin Finck 
412c2c66affSColin Finck     return FALSE;
413c2c66affSColin Finck }
414c2c66affSColin Finck 
415235042a1SKatayama Hirofumi MZ static int CALLBACK
PropSheetProc(HWND hwndDlg,UINT uMsg,LPARAM lParam)416235042a1SKatayama Hirofumi MZ PropSheetProc(HWND hwndDlg, UINT uMsg, LPARAM lParam)
417235042a1SKatayama Hirofumi MZ {
418235042a1SKatayama Hirofumi MZ     // NOTE: This callback is needed to set large icon correctly.
419235042a1SKatayama Hirofumi MZ     HICON hIcon;
420235042a1SKatayama Hirofumi MZ     switch (uMsg)
421235042a1SKatayama Hirofumi MZ     {
422235042a1SKatayama Hirofumi MZ         case PSCB_INITIALIZED:
423235042a1SKatayama Hirofumi MZ         {
424235042a1SKatayama Hirofumi MZ             hIcon = LoadIconW(hApplet, MAKEINTRESOURCEW(IDI_HARDPROF));
425235042a1SKatayama Hirofumi MZ             SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
426235042a1SKatayama Hirofumi MZ             break;
427235042a1SKatayama Hirofumi MZ         }
428235042a1SKatayama Hirofumi MZ     }
429235042a1SKatayama Hirofumi MZ     return 0;
430235042a1SKatayama Hirofumi MZ }
431c2c66affSColin Finck 
432c2c66affSColin Finck static
433c2c66affSColin Finck VOID
HardwareProfileProperties(HWND hwndDlg,PPROFILEDATA pProfileData)434c2c66affSColin Finck HardwareProfileProperties(
435c2c66affSColin Finck     HWND hwndDlg,
436c2c66affSColin Finck     PPROFILEDATA pProfileData)
437c2c66affSColin Finck {
438c2c66affSColin Finck     HPROPSHEETPAGE hpsp;
439c2c66affSColin Finck     PROPSHEETHEADER psh;
440c2c66affSColin Finck     PROPSHEETPAGE psp;
441c2c66affSColin Finck 
442c2c66affSColin Finck     ZeroMemory(&psp, sizeof(psp));
443c2c66affSColin Finck     psp.dwSize = sizeof(psp);
444c2c66affSColin Finck     psp.dwFlags = PSP_DEFAULT;
445c2c66affSColin Finck     psp.hInstance = hApplet;
446c2c66affSColin Finck     psp.pszTemplate = MAKEINTRESOURCE(IDD_HARDWAREPROFILE);
447c2c66affSColin Finck     psp.pfnDlgProc = HardwareProfilePropertiesDlgProc;
448c2c66affSColin Finck 
449c2c66affSColin Finck     hpsp = CreatePropertySheetPage(&psp);
450c2c66affSColin Finck     if (hpsp == NULL)
451c2c66affSColin Finck     {
452c2c66affSColin Finck         return;
453c2c66affSColin Finck     }
454c2c66affSColin Finck 
455c2c66affSColin Finck     ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
456c2c66affSColin Finck     psh.dwSize = sizeof(PROPSHEETHEADER);
457235042a1SKatayama Hirofumi MZ     psh.dwFlags = PSH_PROPTITLE | PSH_USEICONID | PSH_USECALLBACK;
458c2c66affSColin Finck     psh.hwndParent = hwndDlg;
459c2c66affSColin Finck     psh.hInstance = hApplet;
460235042a1SKatayama Hirofumi MZ     psh.pszIcon = MAKEINTRESOURCEW(IDI_HARDPROF);
461c2c66affSColin Finck     psh.pszCaption = pProfileData->pProfiles[pProfileData->dwSelectedProfileIndex].szFriendlyName;
462c2c66affSColin Finck     psh.nPages = 1;
463c2c66affSColin Finck     psh.nStartPage = 0;
464c2c66affSColin Finck     psh.phpage = &hpsp;
465235042a1SKatayama Hirofumi MZ     psh.pfnCallback = PropSheetProc;
466c2c66affSColin Finck 
467c2c66affSColin Finck     PropertySheet(&psh);
468c2c66affSColin Finck }
469c2c66affSColin Finck 
470c2c66affSColin Finck 
471c2c66affSColin Finck static
472c2c66affSColin Finck DWORD
GetUserWaitInterval(VOID)473c2c66affSColin Finck GetUserWaitInterval(VOID)
474c2c66affSColin Finck {
475c2c66affSColin Finck     DWORD dwWaitInterval = 30;
476c2c66affSColin Finck     DWORD dwSize;
477c2c66affSColin Finck     HKEY hKey;
478c2c66affSColin Finck 
479c2c66affSColin Finck     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
480c2c66affSColin Finck                       L"System\\CurrentControlSet\\Control\\IDConfigDB",
481c2c66affSColin Finck                       0,
482c2c66affSColin Finck                       KEY_QUERY_VALUE,
483c2c66affSColin Finck                       &hKey))
484c2c66affSColin Finck         return dwWaitInterval;
485c2c66affSColin Finck 
486c2c66affSColin Finck     dwSize = sizeof(DWORD);
487c2c66affSColin Finck     RegQueryValueExW(hKey,
488c2c66affSColin Finck                      L"UserWaitInterval",
489c2c66affSColin Finck                      NULL,
490c2c66affSColin Finck                      NULL,
491c2c66affSColin Finck                      (LPBYTE)&dwWaitInterval,
492c2c66affSColin Finck                      &dwSize);
493c2c66affSColin Finck 
494c2c66affSColin Finck     RegCloseKey(hKey);
495c2c66affSColin Finck 
496c2c66affSColin Finck     return dwWaitInterval;
497c2c66affSColin Finck }
498c2c66affSColin Finck 
499c2c66affSColin Finck 
500c2c66affSColin Finck static
501c2c66affSColin Finck VOID
SetUserWaitInterval(DWORD dwWaitInterval)502c2c66affSColin Finck SetUserWaitInterval(DWORD dwWaitInterval)
503c2c66affSColin Finck {
504c2c66affSColin Finck     HKEY hKey;
505c2c66affSColin Finck 
506c2c66affSColin Finck     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
507c2c66affSColin Finck                       L"System\\CurrentControlSet\\Control\\IDConfigDB",
508c2c66affSColin Finck                       0,
509c2c66affSColin Finck                       KEY_SET_VALUE,
510c2c66affSColin Finck                       &hKey))
511c2c66affSColin Finck         return;
512c2c66affSColin Finck 
513c2c66affSColin Finck     RegSetValueExW(hKey,
514c2c66affSColin Finck                    L"UserWaitInterval",
515c2c66affSColin Finck                    0,
516c2c66affSColin Finck                    REG_DWORD,
517c2c66affSColin Finck                    (LPBYTE)&dwWaitInterval,
518c2c66affSColin Finck                    sizeof(DWORD));
519c2c66affSColin Finck 
520c2c66affSColin Finck     RegCloseKey(hKey);
521c2c66affSColin Finck }
522c2c66affSColin Finck 
523c2c66affSColin Finck 
524c2c66affSColin Finck static
525c2c66affSColin Finck BOOL
GetProfileCount(LPDWORD lpProfileCount)526c2c66affSColin Finck GetProfileCount(LPDWORD lpProfileCount)
527c2c66affSColin Finck {
528c2c66affSColin Finck     HKEY hKey;
529c2c66affSColin Finck     LONG lError;
530c2c66affSColin Finck 
531c2c66affSColin Finck     *lpProfileCount = 0;
532c2c66affSColin Finck 
533c2c66affSColin Finck     lError = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
534c2c66affSColin Finck                            L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles",
535c2c66affSColin Finck                            0,
536c2c66affSColin Finck                            KEY_READ,
537c2c66affSColin Finck                            &hKey);
538c2c66affSColin Finck     if (lError != ERROR_SUCCESS)
539c2c66affSColin Finck         return FALSE;
540c2c66affSColin Finck 
541c2c66affSColin Finck     lError = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, lpProfileCount,
542c2c66affSColin Finck                               NULL, NULL, NULL, NULL, NULL, NULL, NULL);
543c2c66affSColin Finck 
544c2c66affSColin Finck     RegCloseKey(hKey);
545c2c66affSColin Finck 
546c2c66affSColin Finck     if (lError != ERROR_SUCCESS)
547c2c66affSColin Finck         return FALSE;
548c2c66affSColin Finck 
549c2c66affSColin Finck     return TRUE;
550c2c66affSColin Finck }
551c2c66affSColin Finck 
552c2c66affSColin Finck 
553c2c66affSColin Finck static
554c2c66affSColin Finck VOID
GetProfile(HWND hwndDlg,HKEY hKey,LPWSTR lpName,DWORD dwProfileNumber,PPROFILE pProfile)555c2c66affSColin Finck GetProfile(
556c2c66affSColin Finck     HWND hwndDlg,
557c2c66affSColin Finck     HKEY hKey,
558c2c66affSColin Finck     LPWSTR lpName,
559c2c66affSColin Finck     DWORD dwProfileNumber,
560c2c66affSColin Finck     PPROFILE pProfile)
561c2c66affSColin Finck {
562c2c66affSColin Finck     HKEY hProfileKey;
563c2c66affSColin Finck     DWORD dwSize;
564c2c66affSColin Finck     LONG lError;
565c2c66affSColin Finck 
566c2c66affSColin Finck     lError = RegOpenKeyExW(hKey,
567c2c66affSColin Finck                            lpName,
568c2c66affSColin Finck                            0,
569c2c66affSColin Finck                            KEY_READ,
570c2c66affSColin Finck                            &hProfileKey);
571c2c66affSColin Finck     if (lError != ERROR_SUCCESS)
572c2c66affSColin Finck         return;
573c2c66affSColin Finck 
574c2c66affSColin Finck     dwSize = PROFILE_NAME_LENGTH * sizeof(WCHAR);
575c2c66affSColin Finck     lError = RegQueryValueExW(hProfileKey,
576c2c66affSColin Finck                               L"FriendlyName",
577c2c66affSColin Finck                               NULL,
578c2c66affSColin Finck                               NULL,
579c2c66affSColin Finck                               (LPBYTE)pProfile->szFriendlyName,
580c2c66affSColin Finck                               &dwSize);
581c2c66affSColin Finck     if (lError == ERROR_SUCCESS)
582c2c66affSColin Finck     {
583c2c66affSColin Finck         DPRINT1("Profile: %S\n", pProfile->szFriendlyName);
584c2c66affSColin Finck     }
585c2c66affSColin Finck 
586c2c66affSColin Finck     dwSize = sizeof(DWORD);
587c2c66affSColin Finck     lError = RegQueryValueExW(hProfileKey,
588c2c66affSColin Finck                               L"PreferenceOrder",
589c2c66affSColin Finck                               NULL,
590c2c66affSColin Finck                               NULL,
5910f8439aaSTimo Kreuzer                               (LPBYTE)&pProfile->dwPreferenceOrder,
592c2c66affSColin Finck                               &dwSize);
593c2c66affSColin Finck     if (lError == ERROR_SUCCESS)
594c2c66affSColin Finck     {
595c2c66affSColin Finck         DPRINT1("PreferenceOrder: %lu\n", pProfile->dwPreferenceOrder);
596c2c66affSColin Finck     }
597c2c66affSColin Finck 
598c2c66affSColin Finck     pProfile->dwProfileNumber = dwProfileNumber;
599c2c66affSColin Finck 
600c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFLSTBOX, LB_ADDSTRING, 0, (LPARAM)pProfile->szFriendlyName);
601c2c66affSColin Finck 
602c2c66affSColin Finck     RegCloseKey(hProfileKey);
603c2c66affSColin Finck }
604c2c66affSColin Finck 
605c2c66affSColin Finck 
606c2c66affSColin Finck static
607c2c66affSColin Finck BOOL
GetProfiles(HWND hwndDlg)608c2c66affSColin Finck GetProfiles(HWND hwndDlg)
609c2c66affSColin Finck {
610c2c66affSColin Finck     PPROFILEDATA pProfileData;
611c2c66affSColin Finck     WCHAR szName[8];
612c2c66affSColin Finck     DWORD dwNameLength;
613c2c66affSColin Finck     DWORD dwProfileNumber;
614c2c66affSColin Finck     DWORD dwIndex = 0;
615c2c66affSColin Finck     HKEY hKey;
616c2c66affSColin Finck     LONG lError;
617c2c66affSColin Finck 
618c2c66affSColin Finck     pProfileData = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(PROFILEDATA));
619c2c66affSColin Finck     if (pProfileData == NULL)
620c2c66affSColin Finck         return FALSE;
621c2c66affSColin Finck 
622c2c66affSColin Finck     pProfileData->dwLastProfile = (DWORD)-1;
623c2c66affSColin Finck     pProfileData->dwSelectedProfileIndex = (DWORD)-1;
624c2c66affSColin Finck 
625c2c66affSColin Finck     if (!GetProfileCount(&pProfileData->dwProfileCount))
626c2c66affSColin Finck     {
627c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pProfileData);
628c2c66affSColin Finck         return FALSE;
629c2c66affSColin Finck     }
630c2c66affSColin Finck 
631c2c66affSColin Finck     pProfileData->pProfiles = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
632c2c66affSColin Finck                                         pProfileData->dwProfileCount * sizeof(PROFILE));
633c2c66affSColin Finck     if (pProfileData->pProfiles == NULL)
634c2c66affSColin Finck     {
635c2c66affSColin Finck         HeapFree(GetProcessHeap(), 0, pProfileData);
636c2c66affSColin Finck         return FALSE;
637c2c66affSColin Finck     }
638c2c66affSColin Finck 
639c2c66affSColin Finck     SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pProfileData);
640c2c66affSColin Finck 
641c2c66affSColin Finck     if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
642c2c66affSColin Finck                       L"System\\CurrentControlSet\\Control\\IDConfigDB\\Hardware Profiles",
643c2c66affSColin Finck                       0,
644c2c66affSColin Finck                       KEY_READ,
645c2c66affSColin Finck                       &hKey) != ERROR_SUCCESS)
646c2c66affSColin Finck         return FALSE;
647c2c66affSColin Finck 
648c2c66affSColin Finck     for (dwIndex = 0; dwIndex < pProfileData->dwProfileCount; dwIndex++)
649c2c66affSColin Finck     {
650c2c66affSColin Finck         dwNameLength = 8;
651c2c66affSColin Finck         lError = RegEnumKeyExW(hKey,
652c2c66affSColin Finck                                dwIndex,
653c2c66affSColin Finck                                szName,
654c2c66affSColin Finck                                &dwNameLength,
655c2c66affSColin Finck                                NULL,
656c2c66affSColin Finck                                NULL,
657c2c66affSColin Finck                                NULL,
658c2c66affSColin Finck                                NULL);
659c2c66affSColin Finck         if (lError != ERROR_SUCCESS)
660c2c66affSColin Finck             break;
661c2c66affSColin Finck 
662c2c66affSColin Finck         dwProfileNumber = wcstoul(szName, NULL, 10);
663c2c66affSColin Finck         DPRINT("Profile name: %S\n", szName);
664c2c66affSColin Finck         DPRINT("Profile number: %lu\n", dwProfileNumber);
665c2c66affSColin Finck 
666c2c66affSColin Finck         if ((pProfileData->dwLastProfile == (DWORD)-1) ||
667c2c66affSColin Finck             (pProfileData->dwLastProfile < dwProfileNumber))
668c2c66affSColin Finck             pProfileData->dwLastProfile = dwProfileNumber;
669c2c66affSColin Finck 
670c2c66affSColin Finck         DPRINT("Last Profile number: %lu\n", pProfileData->dwLastProfile);
671c2c66affSColin Finck 
672c2c66affSColin Finck         GetProfile(hwndDlg, hKey, szName, dwProfileNumber, &pProfileData->pProfiles[dwIndex]);
673c2c66affSColin Finck     }
674c2c66affSColin Finck 
675c2c66affSColin Finck     RegCloseKey(hKey);
676c2c66affSColin Finck 
677c2c66affSColin Finck     return TRUE;
678c2c66affSColin Finck }
679c2c66affSColin Finck 
680c2c66affSColin Finck 
681c2c66affSColin Finck static
682c2c66affSColin Finck BOOL
OnInitHardProfDialog(HWND hwndDlg)683eff73544SAmine Khaldi OnInitHardProfDialog(HWND hwndDlg)
684c2c66affSColin Finck {
685c2c66affSColin Finck     DWORD dwWaitInterval;
686c2c66affSColin Finck 
687eff73544SAmine Khaldi     DPRINT("OnInitHardProfDialog()\n");
688c2c66affSColin Finck 
689c2c66affSColin Finck     SendMessage(GetDlgItem(hwndDlg, IDC_HRDPROFUP),
690c2c66affSColin Finck                 BM_SETIMAGE,(WPARAM)IMAGE_ICON,
691c2c66affSColin Finck                 (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_UP)));
692c2c66affSColin Finck     SendMessage(GetDlgItem(hwndDlg, IDC_HRDPROFDWN),
693c2c66affSColin Finck                 BM_SETIMAGE,(WPARAM)IMAGE_ICON,
694c2c66affSColin Finck                 (LPARAM)(HANDLE)LoadIcon(hApplet, MAKEINTRESOURCE(IDI_DOWN)));
695c2c66affSColin Finck 
696c2c66affSColin Finck     if (!GetProfiles(hwndDlg))
697c2c66affSColin Finck         return FALSE;
698c2c66affSColin Finck 
699c2c66affSColin Finck     SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETRANGE, (WPARAM)0, (LPARAM)MAKELONG((SHORT)500, 0));
700c2c66affSColin Finck 
701c2c66affSColin Finck     dwWaitInterval = GetUserWaitInterval();
702c2c66affSColin Finck     if (dwWaitInterval == (DWORD)-1)
703c2c66affSColin Finck     {
704c2c66affSColin Finck         CheckDlgButton(hwndDlg, IDC_HRDPROFWAIT, BST_CHECKED);
705c2c66affSColin Finck         SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETPOS, 0, 30);
706c2c66affSColin Finck         EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), FALSE);
707c2c66affSColin Finck     }
708c2c66affSColin Finck     else
709c2c66affSColin Finck     {
710c2c66affSColin Finck         CheckDlgButton(hwndDlg, IDC_HRDPROFSELECT, BST_CHECKED);
711c2c66affSColin Finck         SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_SETPOS, 0, dwWaitInterval);
712c2c66affSColin Finck     }
713c2c66affSColin Finck 
714c2c66affSColin Finck     return TRUE;
715c2c66affSColin Finck }
716c2c66affSColin Finck 
717c2c66affSColin Finck 
718c2c66affSColin Finck static
719c2c66affSColin Finck VOID
OnOk(HWND hwndDlg)720c2c66affSColin Finck OnOk(HWND hwndDlg)
721c2c66affSColin Finck {
722c2c66affSColin Finck     DWORD dwWaitInterval;
723c2c66affSColin Finck 
724c2c66affSColin Finck     if (IsDlgButtonChecked(hwndDlg, IDC_HRDPROFWAIT) == BST_CHECKED)
725c2c66affSColin Finck     {
726c2c66affSColin Finck         dwWaitInterval = (DWORD)-1;
727c2c66affSColin Finck     }
728c2c66affSColin Finck     else
729c2c66affSColin Finck     {
730c2c66affSColin Finck         dwWaitInterval = LOWORD(SendDlgItemMessageW(hwndDlg, IDC_HRDPROFUPDWN, UDM_GETPOS, 0, 0));
731c2c66affSColin Finck     }
732c2c66affSColin Finck 
733c2c66affSColin Finck     SetUserWaitInterval(dwWaitInterval);
734c2c66affSColin Finck }
735c2c66affSColin Finck 
736c2c66affSColin Finck 
737c2c66affSColin Finck /* Property page dialog callback */
738c2c66affSColin Finck INT_PTR
739c2c66affSColin Finck CALLBACK
HardProfDlgProc(HWND hwndDlg,UINT uMsg,WPARAM wParam,LPARAM lParam)740c2c66affSColin Finck HardProfDlgProc(HWND hwndDlg,
741c2c66affSColin Finck                 UINT uMsg,
742c2c66affSColin Finck                 WPARAM wParam,
743c2c66affSColin Finck                 LPARAM lParam)
744c2c66affSColin Finck {
745c2c66affSColin Finck     PPROFILEDATA pProfileData;
746c2c66affSColin Finck 
747c2c66affSColin Finck     UNREFERENCED_PARAMETER(lParam);
748c2c66affSColin Finck     UNREFERENCED_PARAMETER(wParam);
749c2c66affSColin Finck     UNREFERENCED_PARAMETER(hwndDlg);
750c2c66affSColin Finck 
751c2c66affSColin Finck     pProfileData = (PPROFILEDATA)GetWindowLongPtr(hwndDlg, DWLP_USER);
752c2c66affSColin Finck 
753c2c66affSColin Finck     switch (uMsg)
754c2c66affSColin Finck     {
755c2c66affSColin Finck         case WM_INITDIALOG:
756eff73544SAmine Khaldi             return OnInitHardProfDialog(hwndDlg);
757c2c66affSColin Finck 
758c2c66affSColin Finck         case WM_DESTROY:
759c2c66affSColin Finck             if (pProfileData != NULL)
760c2c66affSColin Finck             {
761c2c66affSColin Finck                 if (pProfileData->pProfiles != NULL)
762c2c66affSColin Finck                     HeapFree(GetProcessHeap(), 0, pProfileData->pProfiles);
763c2c66affSColin Finck                 HeapFree(GetProcessHeap(), 0, pProfileData);
764c2c66affSColin Finck             }
765c2c66affSColin Finck             break;
766c2c66affSColin Finck 
767c2c66affSColin Finck         case WM_COMMAND:
768c2c66affSColin Finck             switch (LOWORD(wParam))
769c2c66affSColin Finck             {
770c2c66affSColin Finck                 case IDC_HRDPROFPROP:
771c2c66affSColin Finck                     HardwareProfileProperties(hwndDlg, pProfileData);
772c2c66affSColin Finck                     break;
773c2c66affSColin Finck 
774c2c66affSColin Finck                 case IDC_HRDPROFCOPY:
775c2c66affSColin Finck                     CopyHardwareProfile(hwndDlg, pProfileData);
776c2c66affSColin Finck                     break;
777c2c66affSColin Finck 
778c2c66affSColin Finck                 case IDC_HRDPROFRENAME:
779c2c66affSColin Finck                     RenameHardwareProfile(hwndDlg, pProfileData);
780c2c66affSColin Finck                     break;
781c2c66affSColin Finck 
782c2c66affSColin Finck                 case IDC_HRDPROFDEL:
783c2c66affSColin Finck                     DeleteHardwareProfile(hwndDlg, pProfileData);
784c2c66affSColin Finck                     break;
785c2c66affSColin Finck 
786c2c66affSColin Finck                 case IDC_HRDPROFUP:
787c2c66affSColin Finck                     MoveHardwareProfile(hwndDlg, pProfileData, TRUE);
788c2c66affSColin Finck                     break;
789c2c66affSColin Finck 
790c2c66affSColin Finck                 case IDC_HRDPROFDWN:
791c2c66affSColin Finck                     MoveHardwareProfile(hwndDlg, pProfileData, FALSE);
792c2c66affSColin Finck                     break;
793c2c66affSColin Finck 
794c2c66affSColin Finck                 case IDC_HRDPROFWAIT:
795c2c66affSColin Finck                     EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), FALSE);
796c2c66affSColin Finck                     return TRUE;
797c2c66affSColin Finck 
798c2c66affSColin Finck                 case IDC_HRDPROFSELECT:
799c2c66affSColin Finck                     EnableWindow(GetDlgItem(hwndDlg, IDC_HRDPROFEDIT), TRUE);
800c2c66affSColin Finck                     return TRUE;
801c2c66affSColin Finck 
802c2c66affSColin Finck                 case IDC_HRDPROFLSTBOX:
803c2c66affSColin Finck                     if (HIWORD(wParam) == LBN_SELCHANGE)
804c2c66affSColin Finck                     {
805c2c66affSColin Finck                         pProfileData->dwSelectedProfileIndex = (DWORD)SendDlgItemMessage(hwndDlg, IDC_HRDPROFLSTBOX, LB_GETCURSEL, 0, 0);
806c2c66affSColin Finck                         UpdateButtons(hwndDlg, pProfileData);
807c2c66affSColin Finck                     }
808c2c66affSColin Finck                     return TRUE;
809c2c66affSColin Finck 
810c2c66affSColin Finck                 case IDOK:
811c2c66affSColin Finck                     OnOk(hwndDlg);
812c2c66affSColin Finck 
813c2c66affSColin Finck                 case IDCANCEL:
814c2c66affSColin Finck                     EndDialog(hwndDlg, LOWORD(wParam));
815c2c66affSColin Finck                     return TRUE;
816c2c66affSColin Finck             }
817c2c66affSColin Finck             break;
818c2c66affSColin Finck     }
819c2c66affSColin Finck 
820c2c66affSColin Finck     return FALSE;
821c2c66affSColin Finck }
822