2 * ReactOS Device Manager Applet
3 * Copyright (C) 2004 - 2005 ReactOS Team
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.
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.
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
19 /* $Id: hwpage.c 19599 2005-11-26 02:12:58Z weiden $
21 * PROJECT: ReactOS devmgr.dll
22 * FILE: lib/devmgr/advprop.c
23 * PURPOSE: ReactOS Device Manager
24 * PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
33 typedef INT_PTR (WINAPI
*PPROPERTYSHEETW
)(LPCPROPSHEETHEADERW
);
34 typedef HPROPSHEETPAGE (WINAPI
*PCREATEPROPERTYSHEETPAGEW
)(LPCPROPSHEETPAGEW
);
35 typedef BOOL (WINAPI
*PDESTROYPROPERTYSHEETPAGE
)(HPROPSHEETPAGE
);
37 typedef struct _DEVADVPROP_INFO
39 HDEVINFO DeviceInfoSet
;
40 PSP_DEVINFO_DATA DeviceInfoData
;
45 } DEVADVPROP_INFO
, *PDEVADVPROP_INFO
;
50 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
58 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
61 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
67 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
72 SetWindowLongPtr(hwndDlg
,
76 /* set the device image */
77 if (SetupDiLoadClassIcon(&dap
->DeviceInfoData
->ClassGuid
,
81 SendDlgItemMessage(hwndDlg
,
88 /* set the device name edit control text */
89 SetDlgItemText(hwndDlg
,
93 /* set the device type edit control text */
94 if (GetDeviceTypeString(dap
->DeviceInfoData
,
96 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
98 SetDlgItemText(hwndDlg
,
103 /* set the device manufacturer edit control text */
104 if (GetDeviceManufacturerString(dap
->DeviceInfoSet
,
107 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
109 SetDlgItemText(hwndDlg
,
114 /* set the device location edit control text */
115 if (GetDeviceLocationString(dap
->DeviceInfoData
->DevInst
,
117 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
119 SetDlgItemText(hwndDlg
,
124 /* set the device status edit control text */
125 if (GetDeviceStatusString(dap
->DeviceInfoData
->DevInst
,
128 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
130 SetDlgItemText(hwndDlg
,
143 /* destroy the device icon */
144 hDevIcon
= (HICON
)SendDlgItemMessage(hwndDlg
,
149 if (hDevIcon
!= NULL
)
151 DestroyIcon(hDevIcon
);
163 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
164 IN HDEVINFO DeviceInfoSet
,
165 IN PSP_DEVINFO_DATA DeviceInfoData
,
166 IN HINSTANCE hComCtl32
,
167 IN LPCWSTR lpMachineName
)
169 PROPSHEETHEADER psh
= {0};
170 PROPSHEETPAGE pspGeneral
= {0};
171 DWORD nPropSheets
= 0;
172 PPROPERTYSHEETW pPropertySheetW
;
173 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
174 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
175 PDEVADVPROP_INFO DevAdvPropInfo
;
176 DWORD PropertySheetType
;
177 HANDLE hMachine
= NULL
;
180 /* we don't want to statically link against comctl32, so find the
181 functions we need dynamically */
183 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
185 pCreatePropertySheetPageW
=
186 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
187 "CreatePropertySheetPageW");
188 pDestroyPropertySheetPage
=
189 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
190 "DestroyPropertySheetPage");
191 if (pPropertySheetW
== NULL
||
192 pCreatePropertySheetPageW
== NULL
||
193 pDestroyPropertySheetPage
== NULL
)
198 if (lpMachineName
!= NULL
)
200 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
202 if (cr
!= CR_SUCCESS
)
208 /* create the internal structure associated with the "General",
209 "Driver", ... pages */
210 DevAdvPropInfo
= HeapAlloc(GetProcessHeap(),
212 sizeof(DEVADVPROP_INFO
));
213 if (DevAdvPropInfo
== NULL
)
218 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
219 DevAdvPropInfo
->DeviceInfoData
= DeviceInfoData
;
220 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
221 DevAdvPropInfo
->hMachine
= hMachine
;
222 DevAdvPropInfo
->szDevName
[0] = L
'\0';
224 /* get the device name */
225 if (GetDeviceDescriptionString(DeviceInfoSet
,
227 DevAdvPropInfo
->szDevName
,
228 sizeof(DevAdvPropInfo
->szDevName
) / sizeof(DevAdvPropInfo
->szDevName
[0])))
230 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
231 psh
.dwFlags
= PSH_PROPTITLE
;
232 psh
.hwndParent
= hWndParent
;
233 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
235 PropertySheetType
= lpMachineName
!= NULL
?
236 DIGCDP_FLAG_REMOTE_ADVANCED
:
237 DIGCDP_FLAG_ADVANCED
;
239 /* find out how many property sheets we need */
240 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
245 PropertySheetType
) &&
248 DPRINT1("SetupDiGetClassDevPropertySheets unexpectedly returned TRUE!\n");
252 if (nPropSheets
!= 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
257 psh
.phpage
= HeapAlloc(GetProcessHeap(),
259 (nPropSheets
+ 1) * sizeof(HPROPSHEETPAGE
));
260 if (psh
.phpage
== NULL
)
265 /* add the "General" property sheet */
266 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
267 pspGeneral
.dwFlags
= PSP_DEFAULT
;
268 pspGeneral
.hInstance
= hDllInstance
;
269 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
270 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
271 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
272 psh
.phpage
[0] = pCreatePropertySheetPageW(&pspGeneral
);
273 if (psh
.phpage
[0] != NULL
)
278 if (nPropSheets
!= 0)
280 /* create the device property sheets */
281 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
284 nPropSheets
+ psh
.nPages
,
292 /* FIXME - add the "Driver" property sheet if necessary */
296 Ret
= pPropertySheetW(&psh
);
298 /* NOTE: no need to destroy the property sheets anymore! */
305 /* in case of failure the property sheets must be destroyed */
310 if (psh
.phpage
[i
] != NULL
)
312 pDestroyPropertySheetPage(psh
.phpage
[i
]);
317 HeapFree(GetProcessHeap(),
322 HeapFree(GetProcessHeap(),
326 if (hMachine
!= NULL
)
328 CM_Disconnect_Machine(hMachine
);
335 /***************************************************************************
337 * DeviceAdvancedPropertiesW
340 * Invokes the device properties dialog, this version may add some property pages
344 * hWndParent: Handle to the parent window
345 * lpMachineName: Machine Name, NULL is the local machine
346 * lpDeviceID: Specifies the device whose properties are to be shown
349 * -1: if errors occured
359 DeviceAdvancedPropertiesW(HWND hWndParent
,
360 LPCWSTR lpMachineName
,
364 SP_DEVINFO_DATA DevInfoData
;
368 /* dynamically load comctl32 */
369 hComCtl32
= LoadAndInitComctl32();
370 if (hComCtl32
!= NULL
)
372 if (lpMachineName
!= NULL
)
374 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
381 hDevInfo
= SetupDiCreateDeviceInfoList(NULL
,
385 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
387 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
388 if (SetupDiOpenDeviceInfo(hDevInfo
,
394 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
401 SetupDiDestroyDeviceInfoList(hDevInfo
);
404 FreeLibrary(hComCtl32
);
411 /***************************************************************************
413 * DeviceAdvancedPropertiesA
416 * Invokes the device properties dialog, this version may add some property pages
420 * hWndParent: Handle to the parent window
421 * lpMachineName: Machine Name, NULL is the local machine
422 * lpDeviceID: Specifies the device whose properties are to be shown
425 * -1: if errors occured
435 DeviceAdvancedPropertiesA(HWND hWndParent
,
436 LPCSTR lpMachineName
,
439 LPWSTR lpMachineNameW
= NULL
;
440 LPWSTR lpDeviceIDW
= NULL
;
443 if (lpMachineName
!= NULL
)
445 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
451 if (lpDeviceID
!= NULL
)
453 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
460 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
465 if (lpMachineNameW
!= NULL
)
467 HeapFree(GetProcessHeap(),
471 if (lpDeviceIDW
!= NULL
)
473 HeapFree(GetProcessHeap(),