simplify displaying the advanced device properties
[reactos.git] / reactos / lib / devmgr / advprop.c
1 /*
2 * ReactOS Device Manager Applet
3 * Copyright (C) 2004 - 2005 ReactOS Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 /* $Id: hwpage.c 19599 2005-11-26 02:12:58Z weiden $
20 *
21 * PROJECT: ReactOS devmgr.dll
22 * FILE: lib/devmgr/advprop.c
23 * PURPOSE: ReactOS Device Manager
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
25 * UPDATE HISTORY:
26 * 04-04-2004 Created
27 */
28 #include <precomp.h>
29
30 #define NDEBUG
31 #include <debug.h>
32
33 typedef INT_PTR (WINAPI *PPROPERTYSHEETW)(LPCPROPSHEETHEADERW);
34
35 INT_PTR
36 DisplayDeviceAdvancedProperties(IN HWND hWndParent,
37 IN HDEVINFO DeviceInfoSet,
38 IN PSP_DEVINFO_DATA DeviceInfoData,
39 IN HINSTANCE hComCtl32)
40 {
41 WCHAR szDevName[255];
42 DWORD RegDataType;
43 PROPSHEETHEADER psh = {0};
44 DWORD nPropSheets = 0;
45 PPROPERTYSHEETW pPropertySheetW;
46 INT_PTR Ret = -1;
47
48 pPropertySheetW = (PPROPERTYSHEETW)GetProcAddress(hComCtl32,
49 "PropertySheetW");
50 if (pPropertySheetW == NULL)
51 {
52 return -1;
53 }
54
55 /* get the device name */
56 if ((SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
57 DeviceInfoData,
58 SPDRP_FRIENDLYNAME,
59 &RegDataType,
60 (PBYTE)szDevName,
61 sizeof(szDevName),
62 NULL) ||
63 SetupDiGetDeviceRegistryProperty(DeviceInfoSet,
64 DeviceInfoData,
65 SPDRP_DEVICEDESC,
66 &RegDataType,
67 (PBYTE)szDevName,
68 sizeof(szDevName),
69 NULL)) &&
70 RegDataType == REG_SZ)
71 {
72 /* FIXME - check string for NULL termination! */
73
74 psh.dwSize = sizeof(PROPSHEETHEADER);
75 psh.dwFlags = PSH_PROPTITLE;
76 psh.hwndParent = hWndParent;
77 psh.pszCaption = szDevName;
78
79 /* find out how many property sheets we need */
80 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet,
81 DeviceInfoData,
82 &psh,
83 0,
84 &nPropSheets,
85 DIGCDP_FLAG_ADVANCED) &&
86 nPropSheets != 0)
87 {
88 DPRINT1("SetupDiGetClassDevPropertySheets unexpectedly returned TRUE!\n");
89 goto Cleanup;
90 }
91
92 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
93 {
94 goto Cleanup;
95 }
96
97 psh.phpage = HeapAlloc(GetProcessHeap(),
98 0,
99 nPropSheets * sizeof(HPROPSHEETPAGE));
100 if (psh.phpage == NULL)
101 {
102 goto Cleanup;
103 }
104
105 /* FIXME - add the "General" and "Driver" pages */
106
107 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet,
108 DeviceInfoData,
109 &psh,
110 nPropSheets,
111 NULL,
112 DIGCDP_FLAG_ADVANCED))
113 {
114 goto Cleanup;
115 }
116
117 Ret = pPropertySheetW(&psh);
118
119 Cleanup:
120 HeapFree(GetProcessHeap(),
121 0,
122 psh.phpage);
123 }
124
125 return Ret;
126 }
127
128 /***************************************************************************
129 * NAME EXPORTED
130 * DeviceAdvancedPropertiesW
131 *
132 * DESCRIPTION
133 * Invokes the device properties dialog, this version may add some property pages
134 * for some devices
135 *
136 * ARGUMENTS
137 * hWndParent: Handle to the parent window
138 * lpMachineName: Machine Name, NULL is the local machine
139 * lpDeviceID: Specifies the device whose properties are to be shown
140 *
141 * RETURN VALUE
142 * -1: if errors occured
143 *
144 * REVISIONS
145 *
146 * NOTE
147 *
148 * @implemented
149 */
150 INT_PTR
151 WINAPI
152 DeviceAdvancedPropertiesW(HWND hWndParent,
153 LPCWSTR lpMachineName,
154 LPCWSTR lpDeviceID)
155 {
156 HDEVINFO hDevInfo;
157 SP_DEVINFO_DATA DevInfoData;
158 HINSTANCE hComCtl32;
159 INT_PTR Ret = -1;
160
161 /* FIXME - handle remote device properties */
162
163 UNREFERENCED_PARAMETER(lpMachineName);
164
165 /* dynamically load comctl32 */
166 hComCtl32 = LoadAndInitComctl32();
167 if (hComCtl32 != NULL)
168 {
169 hDevInfo = SetupDiCreateDeviceInfoList(NULL,
170 hWndParent);
171 if (hDevInfo != INVALID_HANDLE_VALUE)
172 {
173 DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
174 if (SetupDiOpenDeviceInfo(hDevInfo,
175 lpDeviceID,
176 hWndParent,
177 0,
178 &DevInfoData))
179 {
180 Ret = DisplayDeviceAdvancedProperties(hWndParent,
181 hDevInfo,
182 &DevInfoData,
183 hComCtl32);
184 }
185
186 SetupDiDestroyDeviceInfoList(hDevInfo);
187 }
188 FreeLibrary(hComCtl32);
189 }
190
191 return Ret;
192 }
193
194 /***************************************************************************
195 * NAME EXPORTED
196 * DeviceAdvancedPropertiesA
197 *
198 * DESCRIPTION
199 * Invokes the device properties dialog, this version may add some property pages
200 * for some devices
201 *
202 * ARGUMENTS
203 * hWndParent: Handle to the parent window
204 * lpMachineName: Machine Name, NULL is the local machine
205 * lpDeviceID: Specifies the device whose properties are to be shown
206 *
207 * RETURN VALUE
208 * -1: if errors occured
209 *
210 * REVISIONS
211 *
212 * NOTE
213 *
214 * @implemented
215 */
216 INT_PTR
217 WINAPI
218 DeviceAdvancedPropertiesA(HWND hWndParent,
219 LPCSTR lpMachineName,
220 LPCSTR lpDeviceID)
221 {
222 LPWSTR lpMachineNameW = NULL;
223 LPWSTR lpDeviceIDW = NULL;
224 INT_PTR Ret = -1;
225
226 if (lpMachineName != NULL)
227 {
228 if (!(lpMachineNameW = ConvertMultiByteToUnicode(lpMachineName,
229 CP_ACP)))
230 {
231 goto Cleanup;
232 }
233 }
234 if (lpDeviceID != NULL)
235 {
236 if (!(lpDeviceIDW = ConvertMultiByteToUnicode(lpDeviceID,
237 CP_ACP)))
238 {
239 goto Cleanup;
240 }
241 }
242
243 Ret = DeviceAdvancedPropertiesW(hWndParent,
244 lpMachineNameW,
245 lpDeviceIDW);
246
247 Cleanup:
248 HeapFree(GetProcessHeap(),
249 0,
250 lpMachineNameW);
251 HeapFree(GetProcessHeap(),
252 0,
253 lpDeviceIDW);
254
255 return Ret;
256 }