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
);
44 typedef struct _DEVADVPROP_INFO
46 HDEVINFO DeviceInfoSet
;
47 PSP_DEVINFO_DATA DeviceInfoData
;
54 } DEVADVPROP_INFO
, *PDEVADVPROP_INFO
;
58 InitDevUsageActions(IN HWND hwndDlg
,
60 IN PDEVADVPROP_INFO dap
)
67 DEVENABLEACTION Action
;
70 {IDS_ENABLEDEVICE
, DEA_ENABLE
},
71 {IDS_DISABLEDEVICE
, DEA_DISABLE
},
75 i
!= sizeof(Actions
) / sizeof(Actions
[0]);
78 /* fill in the device usage combo box */
79 if (LoadString(hDllInstance
,
82 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
84 Index
= (INT
)SendMessage(hComboBox
,
90 SendMessage(hComboBox
,
93 (LPARAM
)Actions
[i
].Action
);
95 switch (Actions
[i
].Action
)
98 if (dap
->DeviceEnabled
)
100 SendMessage(hComboBox
,
108 if (!dap
->DeviceEnabled
)
110 SendMessage(hComboBox
,
126 static DEVENABLEACTION
127 GetSelectedUsageAction(IN HWND hComboBox
)
130 DEVENABLEACTION Ret
= DEA_UNKNOWN
;
132 Index
= (INT
)SendMessage(hComboBox
,
138 INT iRet
= SendMessage(hComboBox
,
142 if (iRet
!= CB_ERR
&& iRet
< (INT
)DEA_UNKNOWN
)
144 Ret
= (DEVENABLEACTION
)iRet
;
153 ApplyGeneralSettings(IN HWND hwndDlg
,
154 IN PDEVADVPROP_INFO dap
)
156 DEVENABLEACTION SelectedUsageAction
;
158 SelectedUsageAction
= GetSelectedUsageAction(GetDlgItem(hwndDlg
,
160 if (SelectedUsageAction
!= DEA_UNKNOWN
)
162 switch (SelectedUsageAction
)
165 if (!dap
->DeviceEnabled
)
167 /* FIXME - enable device */
172 if (dap
->DeviceEnabled
)
174 /* FIXME - disable device */
182 /* disable the apply button */
183 PropSheet_UnChanged(GetParent(hwndDlg
),
190 UpdateDevInfo(IN HWND hwndDlg
,
191 IN PDEVADVPROP_INFO dap
)
196 /* get the device name */
197 if (GetDeviceDescriptionString(dap
->DeviceInfoSet
,
200 sizeof(dap
->szDevName
) / sizeof(dap
->szDevName
[0])))
202 PropSheet_SetTitle(GetParent(hwndDlg
),
207 /* set the device image */
208 if (SetupDiLoadClassIcon(&dap
->DeviceInfoData
->ClassGuid
,
212 HICON hOldIcon
= (HICON
)SendDlgItemMessage(hwndDlg
,
217 if (hOldIcon
!= NULL
)
219 DestroyIcon(hOldIcon
);
223 /* set the device name edit control text */
224 SetDlgItemText(hwndDlg
,
228 /* set the device type edit control text */
229 if (GetDeviceTypeString(dap
->DeviceInfoData
,
231 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
233 SetDlgItemText(hwndDlg
,
238 /* set the device manufacturer edit control text */
239 if (GetDeviceManufacturerString(dap
->DeviceInfoSet
,
242 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
244 SetDlgItemText(hwndDlg
,
249 /* set the device location edit control text */
250 if (GetDeviceLocationString(dap
->DeviceInfoData
->DevInst
,
252 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
254 SetDlgItemText(hwndDlg
,
259 /* set the device status edit control text */
260 if (GetDeviceStatusString(dap
->DeviceInfoData
->DevInst
,
263 sizeof(dap
->szTemp
) / sizeof(dap
->szTemp
[0])))
265 SetDlgItemText(hwndDlg
,
270 /* check if the device can be enabled/disabled */
271 hDevUsage
= GetDlgItem(hwndDlg
,
274 if (!CanDisableDevice(dap
->DeviceInfoData
->DevInst
,
278 dap
->CanDisable
= FALSE
;
281 if (!IsDeviceEnabled(dap
->DeviceInfoData
->DevInst
,
283 &dap
->DeviceEnabled
))
285 dap
->DeviceEnabled
= FALSE
;
288 /* enable/disable the device usage controls */
289 EnableWindow(GetDlgItem(hwndDlg
,
292 EnableWindow(hDevUsage
,
295 /* clear the combobox */
296 SendMessage(hDevUsage
,
302 InitDevUsageActions(hwndDlg
,
307 /* finally, disable the apply button */
308 PropSheet_UnChanged(GetParent(hwndDlg
),
315 AdvPropGeneralDlgProc(IN HWND hwndDlg
,
320 PDEVADVPROP_INFO dap
;
323 dap
= (PDEVADVPROP_INFO
)GetWindowLongPtr(hwndDlg
,
326 if (dap
!= NULL
|| uMsg
== WM_INITDIALOG
)
332 switch (LOWORD(wParam
))
336 if (HIWORD(wParam
) == CBN_SELCHANGE
)
338 PropSheet_Changed(GetParent(hwndDlg
),
349 NMHDR
*hdr
= (NMHDR
*)lParam
;
353 ApplyGeneralSettings(hwndDlg
,
362 dap
= (PDEVADVPROP_INFO
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
365 SetWindowLongPtr(hwndDlg
,
369 UpdateDevInfo(hwndDlg
,
376 case WM_DEVICECHANGE
:
378 /* FIXME - don't call UpdateDevInfo in all events */
379 UpdateDevInfo(hwndDlg
,
388 /* destroy the device icon */
389 hDevIcon
= (HICON
)SendDlgItemMessage(hwndDlg
,
394 if (hDevIcon
!= NULL
)
396 DestroyIcon(hDevIcon
);
408 DisplayDeviceAdvancedProperties(IN HWND hWndParent
,
409 IN HDEVINFO DeviceInfoSet
,
410 IN PSP_DEVINFO_DATA DeviceInfoData
,
411 IN HINSTANCE hComCtl32
,
412 IN LPCWSTR lpMachineName
)
414 PROPSHEETHEADER psh
= {0};
415 PROPSHEETPAGE pspGeneral
= {0};
416 DWORD nPropSheets
= 0;
417 PPROPERTYSHEETW pPropertySheetW
;
418 PCREATEPROPERTYSHEETPAGEW pCreatePropertySheetPageW
;
419 PDESTROYPROPERTYSHEETPAGE pDestroyPropertySheetPage
;
420 PDEVADVPROP_INFO DevAdvPropInfo
;
421 DWORD PropertySheetType
;
422 HANDLE hMachine
= NULL
;
425 /* we don't want to statically link against comctl32, so find the
426 functions we need dynamically */
428 (PPROPERTYSHEETW
)GetProcAddress(hComCtl32
,
430 pCreatePropertySheetPageW
=
431 (PCREATEPROPERTYSHEETPAGEW
)GetProcAddress(hComCtl32
,
432 "CreatePropertySheetPageW");
433 pDestroyPropertySheetPage
=
434 (PDESTROYPROPERTYSHEETPAGE
)GetProcAddress(hComCtl32
,
435 "DestroyPropertySheetPage");
436 if (pPropertySheetW
== NULL
||
437 pCreatePropertySheetPageW
== NULL
||
438 pDestroyPropertySheetPage
== NULL
)
443 if (lpMachineName
!= NULL
)
445 CONFIGRET cr
= CM_Connect_Machine(lpMachineName
,
447 if (cr
!= CR_SUCCESS
)
453 /* create the internal structure associated with the "General",
454 "Driver", ... pages */
455 DevAdvPropInfo
= HeapAlloc(GetProcessHeap(),
457 sizeof(DEVADVPROP_INFO
));
458 if (DevAdvPropInfo
== NULL
)
463 DevAdvPropInfo
->DeviceInfoSet
= DeviceInfoSet
;
464 DevAdvPropInfo
->DeviceInfoData
= DeviceInfoData
;
465 DevAdvPropInfo
->hComCtl32
= hComCtl32
;
466 DevAdvPropInfo
->hMachine
= hMachine
;
467 DevAdvPropInfo
->szDevName
[0] = L
'\0';
469 psh
.dwSize
= sizeof(PROPSHEETHEADER
);
470 psh
.dwFlags
= PSH_PROPTITLE
| PSH_NOAPPLYNOW
;
471 psh
.hwndParent
= hWndParent
;
472 psh
.pszCaption
= DevAdvPropInfo
->szDevName
;
474 PropertySheetType
= lpMachineName
!= NULL
?
475 DIGCDP_FLAG_REMOTE_ADVANCED
:
476 DIGCDP_FLAG_ADVANCED
;
478 /* find out how many property sheets we need */
479 if (SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
484 PropertySheetType
) &&
487 DPRINT1("SetupDiGetClassDevPropertySheets unexpectedly returned TRUE!\n");
491 if (nPropSheets
!= 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER
)
496 psh
.phpage
= HeapAlloc(GetProcessHeap(),
498 (nPropSheets
+ 1) * sizeof(HPROPSHEETPAGE
));
499 if (psh
.phpage
== NULL
)
504 /* add the "General" property sheet */
505 pspGeneral
.dwSize
= sizeof(PROPSHEETPAGE
);
506 pspGeneral
.dwFlags
= PSP_DEFAULT
;
507 pspGeneral
.hInstance
= hDllInstance
;
508 pspGeneral
.pszTemplate
= (LPCWSTR
)MAKEINTRESOURCE(IDD_DEVICEGENERAL
);
509 pspGeneral
.pfnDlgProc
= AdvPropGeneralDlgProc
;
510 pspGeneral
.lParam
= (LPARAM
)DevAdvPropInfo
;
511 psh
.phpage
[0] = pCreatePropertySheetPageW(&pspGeneral
);
512 if (psh
.phpage
[0] != NULL
)
517 if (nPropSheets
!= 0)
519 /* create the device property sheets */
520 if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet
,
523 nPropSheets
+ psh
.nPages
,
531 /* FIXME - add the "Driver" property sheet if necessary */
535 Ret
= pPropertySheetW(&psh
);
537 /* NOTE: no need to destroy the property sheets anymore! */
544 /* in case of failure the property sheets must be destroyed */
549 if (psh
.phpage
[i
] != NULL
)
551 pDestroyPropertySheetPage(psh
.phpage
[i
]);
556 HeapFree(GetProcessHeap(),
560 HeapFree(GetProcessHeap(),
564 if (hMachine
!= NULL
)
566 CM_Disconnect_Machine(hMachine
);
573 /***************************************************************************
575 * DeviceAdvancedPropertiesW
578 * Invokes the device properties dialog, this version may add some property pages
582 * hWndParent: Handle to the parent window
583 * lpMachineName: Machine Name, NULL is the local machine
584 * lpDeviceID: Specifies the device whose properties are to be shown
587 * -1: if errors occured
597 DeviceAdvancedPropertiesW(HWND hWndParent
,
598 LPCWSTR lpMachineName
,
602 SP_DEVINFO_DATA DevInfoData
;
606 /* dynamically load comctl32 */
607 hComCtl32
= LoadAndInitComctl32();
608 if (hComCtl32
!= NULL
)
610 if (lpMachineName
!= NULL
)
612 hDevInfo
= SetupDiCreateDeviceInfoListEx(NULL
,
619 hDevInfo
= SetupDiCreateDeviceInfoList(NULL
,
623 if (hDevInfo
!= INVALID_HANDLE_VALUE
)
625 DevInfoData
.cbSize
= sizeof(SP_DEVINFO_DATA
);
626 if (SetupDiOpenDeviceInfo(hDevInfo
,
632 Ret
= DisplayDeviceAdvancedProperties(hWndParent
,
639 SetupDiDestroyDeviceInfoList(hDevInfo
);
642 FreeLibrary(hComCtl32
);
649 /***************************************************************************
651 * DeviceAdvancedPropertiesA
654 * Invokes the device properties dialog, this version may add some property pages
658 * hWndParent: Handle to the parent window
659 * lpMachineName: Machine Name, NULL is the local machine
660 * lpDeviceID: Specifies the device whose properties are to be shown
663 * -1: if errors occured
673 DeviceAdvancedPropertiesA(HWND hWndParent
,
674 LPCSTR lpMachineName
,
677 LPWSTR lpMachineNameW
= NULL
;
678 LPWSTR lpDeviceIDW
= NULL
;
681 if (lpMachineName
!= NULL
)
683 if (!(lpMachineNameW
= ConvertMultiByteToUnicode(lpMachineName
,
689 if (lpDeviceID
!= NULL
)
691 if (!(lpDeviceIDW
= ConvertMultiByteToUnicode(lpDeviceID
,
698 Ret
= DeviceAdvancedPropertiesW(hWndParent
,
703 if (lpMachineNameW
!= NULL
)
705 HeapFree(GetProcessHeap(),
709 if (lpDeviceIDW
!= NULL
)
711 HeapFree(GetProcessHeap(),