--- trunk/reactos/lib/devmgr/En.rc 2005-12-01 15:37:00 UTC (rev 19797)
+++ trunk/reactos/lib/devmgr/En.rc 2005-12-01 16:02:15 UTC (rev 19798)
@@ -12,6 +12,9 @@
IDS_UNKNOWN "Unknown"
IDS_LOCATIONSTR "Location %1!u! (%2)"
IDS_DEVCODE " (Code %1!u!)"
+ IDS_ENABLEDEVICE "Use this device (enable)"
+ IDS_DISABLEDEVICE "Do not use this device (disable)"
+ IDS_UNKNOWNDEVICE "Unknown device"
END
STRINGTABLE
@@ -100,6 +103,6 @@
GROUPBOX "Device status", IDC_DEVSTATUSGROUP, 7, 83, 238, 100
EDITTEXT IDC_DEVSTATUS, 14, 96, 224, 61, NOT WS_TABSTOP | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | WS_VSCROLL
PUSHBUTTON "&Troubleshoot...", IDC_TROUBLESHOOT, 148, 163, 90, 15
- LTEXT "&Device usage:", -1, 7, 188, 222, 8
- COMBOBOX IDC_DEVUSAGE, 7, 198, 239, 40, CBS_DROPDOWNLIST | WS_VSCROLL
+ LTEXT "&Device usage:", IDC_DEVUSAGELABEL, 7, 188, 222, 8, WS_DISABLED
+ COMBOBOX IDC_DEVUSAGE, 7, 198, 239, 40, CBS_DROPDOWNLIST | WS_VSCROLL | WS_DISABLED
END
--- trunk/reactos/lib/devmgr/advprop.c 2005-12-01 15:37:00 UTC (rev 19797)
+++ trunk/reactos/lib/devmgr/advprop.c 2005-12-01 16:02:15 UTC (rev 19798)
@@ -34,17 +34,282 @@
typedef HPROPSHEETPAGE (WINAPI *PCREATEPROPERTYSHEETPAGEW)(LPCPROPSHEETPAGEW);
typedef BOOL (WINAPI *PDESTROYPROPERTYSHEETPAGE)(HPROPSHEETPAGE);
+typedef enum
+{
+ DEA_DISABLE = 0,
+ DEA_ENABLE,
+ DEA_UNKNOWN
+} DEVENABLEACTION;
+
typedef struct _DEVADVPROP_INFO
{
HDEVINFO DeviceInfoSet;
PSP_DEVINFO_DATA DeviceInfoData;
HINSTANCE hComCtl32;
HANDLE hMachine;
+ BOOL CanDisable;
+ BOOL DeviceEnabled;
WCHAR szDevName[255];
WCHAR szTemp[255];
} DEVADVPROP_INFO, *PDEVADVPROP_INFO;
+static VOID
+InitDevUsageActions(IN HWND hwndDlg,
+ IN HWND hComboBox,
+ IN PDEVADVPROP_INFO dap)
+{
+ INT Index;
+ UINT i;
+ struct
+ {
+ UINT szId;
+ DEVENABLEACTION Action;
+ } Actions[] =
+ {
+ {IDS_ENABLEDEVICE, DEA_ENABLE},
+ {IDS_DISABLEDEVICE, DEA_DISABLE},
+ };
+
+ for (i = 0;
+ i != sizeof(Actions) / sizeof(Actions[0]);
+ i++)
+ {
+ /* fill in the device usage combo box */
+ if (LoadString(hDllInstance,
+ Actions[i].szId,
+ dap->szTemp,
+ sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
+ {
+ Index = (INT)SendMessage(hComboBox,
+ CB_ADDSTRING,
+ 0,
+ (LPARAM)dap->szTemp);
+ if (Index != CB_ERR)
+ {
+ SendMessage(hComboBox,
+ CB_SETITEMDATA,
+ (WPARAM)Index,
+ (LPARAM)Actions[i].Action);
+
+ switch (Actions[i].Action)
+ {
+ case DEA_ENABLE:
+ if (dap->DeviceEnabled)
+ {
+ SendMessage(hComboBox,
+ CB_SETCURSEL,
+ (WPARAM)Index,
+ 0);
+ }
+ break;
+
+ case DEA_DISABLE:
+ if (!dap->DeviceEnabled)
+ {
+ SendMessage(hComboBox,
+ CB_SETCURSEL,
+ (WPARAM)Index,
+ 0);
+ }
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+ }
+}
+
+
+static DEVENABLEACTION
+GetSelectedUsageAction(IN HWND hComboBox)
+{
+ INT Index;
+ DEVENABLEACTION Ret = DEA_UNKNOWN;
+
+ Index = (INT)SendMessage(hComboBox,
+ CB_GETCURSEL,
+ 0,
+ 0);
+ if (Index != CB_ERR)
+ {
+ INT iRet = SendMessage(hComboBox,
+ CB_GETITEMDATA,
+ (WPARAM)Index,
+ 0);
+ if (iRet != CB_ERR && iRet < (INT)DEA_UNKNOWN)
+ {
+ Ret = (DEVENABLEACTION)iRet;
+ }
+ }
+
+ return Ret;
+}
+
+
+static VOID
+ApplyGeneralSettings(IN HWND hwndDlg,
+ IN PDEVADVPROP_INFO dap)
+{
+ DEVENABLEACTION SelectedUsageAction;
+
+ SelectedUsageAction = GetSelectedUsageAction(GetDlgItem(hwndDlg,
+ IDC_DEVUSAGE));
+ if (SelectedUsageAction != DEA_UNKNOWN)
+ {
+ switch (SelectedUsageAction)
+ {
+ case DEA_ENABLE:
+ if (!dap->DeviceEnabled)
+ {
+ /* FIXME - enable device */
+ }
+ break;
+
+ case DEA_DISABLE:
+ if (dap->DeviceEnabled)
+ {
+ /* FIXME - disable device */
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ /* disable the apply button */
+ PropSheet_UnChanged(GetParent(hwndDlg),
+ hwndDlg);
+ }
+}
+
+
+static VOID
+UpdateDevInfo(IN HWND hwndDlg,
+ IN PDEVADVPROP_INFO dap)
+{
+ HICON hIcon;
+ HWND hDevUsage;
+
+ /* get the device name */
+ if (GetDeviceDescriptionString(dap->DeviceInfoSet,
+ dap->DeviceInfoData,
+ dap->szDevName,
+ sizeof(dap->szDevName) / sizeof(dap->szDevName[0])))
+ {
+ PropSheet_SetTitle(GetParent(hwndDlg),
+ PSH_PROPTITLE,
+ dap->szDevName);
+ }
+
+ /* set the device image */
+ if (SetupDiLoadClassIcon(&dap->DeviceInfoData->ClassGuid,
+ &hIcon,
+ NULL))
+ {
+ HICON hOldIcon = (HICON)SendDlgItemMessage(hwndDlg,
+ IDC_DEVICON,
+ STM_SETICON,
+ (WPARAM)hIcon,
+ 0);
+ if (hOldIcon != NULL)
+ {
+ DestroyIcon(hOldIcon);
+ }
+ }
+
+ /* set the device name edit control text */
+ SetDlgItemText(hwndDlg,
+ IDC_DEVNAME,
+ dap->szDevName);
+
+ /* set the device type edit control text */
+ if (GetDeviceTypeString(dap->DeviceInfoData,
+ dap->szTemp,
+ sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
+ {
+ SetDlgItemText(hwndDlg,
+ IDC_DEVTYPE,
+ dap->szTemp);
+ }
+
+ /* set the device manufacturer edit control text */
+ if (GetDeviceManufacturerString(dap->DeviceInfoSet,
+ dap->DeviceInfoData,
+ dap->szTemp,
+ sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
+ {
+ SetDlgItemText(hwndDlg,
+ IDC_DEVMANUFACTURER,
+ dap->szTemp);
+ }
+
+ /* set the device location edit control text */
+ if (GetDeviceLocationString(dap->DeviceInfoData->DevInst,
+ dap->szTemp,
+ sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
+ {
+ SetDlgItemText(hwndDlg,
+ IDC_DEVLOCATION,
+ dap->szTemp);
+ }
+
+ /* set the device status edit control text */
+ if (GetDeviceStatusString(dap->DeviceInfoData->DevInst,
+ dap->hMachine,
+ dap->szTemp,
+ sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
+ {
+ SetDlgItemText(hwndDlg,
+ IDC_DEVSTATUS,
+ dap->szTemp);
+ }
+
+ /* check if the device can be enabled/disabled */
+ hDevUsage = GetDlgItem(hwndDlg,
+ IDC_DEVUSAGE);
+
+ if (!CanDisableDevice(dap->DeviceInfoData->DevInst,
+ dap->hMachine,
+ &dap->CanDisable))
+ {
+ dap->CanDisable = FALSE;
+ }
+
+ if (!IsDeviceEnabled(dap->DeviceInfoData->DevInst,
+ dap->hMachine,
+ &dap->DeviceEnabled))
+ {
+ dap->DeviceEnabled = FALSE;
+ }
+
+ /* enable/disable the device usage controls */
+ EnableWindow(GetDlgItem(hwndDlg,
+ IDC_DEVUSAGELABEL),
+ dap->CanDisable);
+ EnableWindow(hDevUsage,
+ dap->CanDisable);
+
+ /* clear the combobox */
+ SendMessage(hDevUsage,
+ CB_RESETCONTENT,
+ 0,
+ 0);
+ if (dap->CanDisable)
+ {
+ InitDevUsageActions(hwndDlg,
+ hDevUsage,
+ dap);
+ }
+
+ /* finally, disable the apply button */
+ PropSheet_UnChanged(GetParent(hwndDlg),
+ hwndDlg);
+}
+
+
static INT_PTR
CALLBACK
AdvPropGeneralDlgProc(IN HWND hwndDlg,
@@ -62,80 +327,60 @@
{
switch (uMsg)
{
+ case WM_COMMAND:
+ {
+ switch (LOWORD(wParam))
+ {
+ case IDC_DEVUSAGE:
+ {
+ if (HIWORD(wParam) == CBN_SELCHANGE)
+ {
+ PropSheet_Changed(GetParent(hwndDlg),
+ hwndDlg);
+ }
+ break;
+ }
+ }
+ break;
+ }
+
+ case WM_NOTIFY:
+ {
+ NMHDR *hdr = (NMHDR*)lParam;
+ switch (hdr->code)
+ {
+ case PSN_APPLY:
+ ApplyGeneralSettings(hwndDlg,
+ dap);
+ break;
+ }
+ break;
+ }
+
case WM_INITDIALOG:
{
dap = (PDEVADVPROP_INFO)((LPPROPSHEETPAGE)lParam)->lParam;
if (dap != NULL)
{
- HICON hIcon;
-
SetWindowLongPtr(hwndDlg,
DWL_USER,
(DWORD_PTR)dap);
- /* set the device image */
- if (SetupDiLoadClassIcon(&dap->DeviceInfoData->ClassGuid,
- &hIcon,
- NULL))
- {
- SendDlgItemMessage(hwndDlg,
- IDC_DEVICON,
- STM_SETICON,
- (WPARAM)hIcon,
- 0);
- }
-
- /* set the device name edit control text */
- SetDlgItemText(hwndDlg,
- IDC_DEVNAME,
- dap->szDevName);
-
- /* set the device type edit control text */
- if (GetDeviceTypeString(dap->DeviceInfoData,
- dap->szTemp,
- sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
- {
- SetDlgItemText(hwndDlg,
- IDC_DEVTYPE,
- dap->szTemp);
- }
-
- /* set the device manufacturer edit control text */
- if (GetDeviceManufacturerString(dap->DeviceInfoSet,
- dap->DeviceInfoData,
- dap->szTemp,
- sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
- {
- SetDlgItemText(hwndDlg,
- IDC_DEVMANUFACTURER,
- dap->szTemp);
- }
-
- /* set the device location edit control text */
- if (GetDeviceLocationString(dap->DeviceInfoData->DevInst,
- dap->szTemp,
- sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
- {
- SetDlgItemText(hwndDlg,
- IDC_DEVLOCATION,
- dap->szTemp);
- }
-
- /* set the device status edit control text */
- if (GetDeviceStatusString(dap->DeviceInfoData->DevInst,
- dap->hMachine,
- dap->szTemp,
- sizeof(dap->szTemp) / sizeof(dap->szTemp[0])))
- {
- SetDlgItemText(hwndDlg,
- IDC_DEVSTATUS,
- dap->szTemp);
- }
+ UpdateDevInfo(hwndDlg,
+ dap);
}
Ret = TRUE;
break;
}
+ case WM_DEVICECHANGE:
+ {
+ /* FIXME - don't call UpdateDevInfo in all events */
+ UpdateDevInfo(hwndDlg,
+ dap);
+ break;
+ }
+
case WM_DESTROY:
{
HICON hDevIcon;
@@ -221,106 +466,99 @@
DevAdvPropInfo->hMachine = hMachine;
DevAdvPropInfo->szDevName[0] = L'\0';
- /* get the device name */
- if (GetDeviceDescriptionString(DeviceInfoSet,
- DeviceInfoData,
- DevAdvPropInfo->szDevName,
- sizeof(DevAdvPropInfo->szDevName) / sizeof(DevAdvPropInfo->szDevName[0])))
+ psh.dwSize = sizeof(PROPSHEETHEADER);
+ psh.dwFlags = PSH_PROPTITLE | PSH_NOAPPLYNOW;
+ psh.hwndParent = hWndParent;
+ psh.pszCaption = DevAdvPropInfo->szDevName;
+
+ PropertySheetType = lpMachineName != NULL ?
+ DIGCDP_FLAG_REMOTE_ADVANCED :
+ DIGCDP_FLAG_ADVANCED;
+
+ /* find out how many property sheets we need */
+ if (SetupDiGetClassDevPropertySheets(DeviceInfoSet,
+ DeviceInfoData,
+ &psh,
+ 0,
+ &nPropSheets,
+ PropertySheetType) &&
+ nPropSheets != 0)
{
- psh.dwSize = sizeof(PROPSHEETHEADER);
- psh.dwFlags = PSH_PROPTITLE;
- psh.hwndParent = hWndParent;
- psh.pszCaption = DevAdvPropInfo->szDevName;
+ DPRINT1("SetupDiGetClassDevPropertySheets unexpectedly returned TRUE!\n");
+ goto Cleanup;
+ }
- PropertySheetType = lpMachineName != NULL ?
- DIGCDP_FLAG_REMOTE_ADVANCED :
- DIGCDP_FLAG_ADVANCED;
+ if (nPropSheets != 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
+ {
+ goto Cleanup;
+ }
- /* find out how many property sheets we need */
- if (SetupDiGetClassDevPropertySheets(DeviceInfoSet,
- DeviceInfoData,
- &psh,
- 0,
- &nPropSheets,
- PropertySheetType) &&
- nPropSheets != 0)
- {
- DPRINT1("SetupDiGetClassDevPropertySheets unexpectedly returned TRUE!\n");
- goto Cleanup;
- }
+ psh.phpage = HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ (nPropSheets + 1) * sizeof(HPROPSHEETPAGE));
+ if (psh.phpage == NULL)
+ {
+ goto Cleanup;
+ }
- if (nPropSheets != 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER)
- {
- goto Cleanup;
- }
+ /* add the "General" property sheet */
+ pspGeneral.dwSize = sizeof(PROPSHEETPAGE);
+ pspGeneral.dwFlags = PSP_DEFAULT;
+ pspGeneral.hInstance = hDllInstance;
+ pspGeneral.pszTemplate = (LPCWSTR)MAKEINTRESOURCE(IDD_DEVICEGENERAL);
+ pspGeneral.pfnDlgProc = AdvPropGeneralDlgProc;
+ pspGeneral.lParam = (LPARAM)DevAdvPropInfo;
+ psh.phpage[0] = pCreatePropertySheetPageW(&pspGeneral);
+ if (psh.phpage[0] != NULL)
+ {
+ psh.nPages++;
+ }
- psh.phpage = HeapAlloc(GetProcessHeap(),
- HEAP_ZERO_MEMORY,
- (nPropSheets + 1) * sizeof(HPROPSHEETPAGE));
- if (psh.phpage == NULL)
+ if (nPropSheets != 0)
+ {
+ /* create the device property sheets */
+ if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet,
+ DeviceInfoData,
+ &psh,
+ nPropSheets + psh.nPages,
+ NULL,
+ PropertySheetType))
{
goto Cleanup;
}
+ }
- /* add the "General" property sheet */
- pspGeneral.dwSize = sizeof(PROPSHEETPAGE);
- pspGeneral.dwFlags = PSP_DEFAULT;
- pspGeneral.hInstance = hDllInstance;
- pspGeneral.pszTemplate = (LPCWSTR)MAKEINTRESOURCE(IDD_DEVICEGENERAL);
- pspGeneral.pfnDlgProc = AdvPropGeneralDlgProc;
- pspGeneral.lParam = (LPARAM)DevAdvPropInfo;
- psh.phpage[0] = pCreatePropertySheetPageW(&pspGeneral);
- if (psh.phpage[0] != NULL)
- {
- psh.nPages++;
- }
+ /* FIXME - add the "Driver" property sheet if necessary */
- if (nPropSheets != 0)
- {
- /* create the device property sheets */
- if (!SetupDiGetClassDevPropertySheets(DeviceInfoSet,
- DeviceInfoData,
- &psh,
- nPropSheets + psh.nPages,
- NULL,
- PropertySheetType))
- {
- goto Cleanup;
- }
- }
+ if (psh.nPages != 0)
+ {
+ Ret = pPropertySheetW(&psh);
- /* FIXME - add the "Driver" property sheet if necessary */
+ /* NOTE: no need to destroy the property sheets anymore! */
+ }
+ else
+ {
+ UINT i;
- if (psh.nPages != 0)
+Cleanup:
+ /* in case of failure the property sheets must be destroyed */
+ for (i = 0;
+ i < psh.nPages;
+ i++)
{
- Ret = pPropertySheetW(&psh);
-
- /* NOTE: no need to destroy the property sheets anymore! */
- }
- else
- {
- UINT i;
-
-Cleanup:
- /* in case of failure the property sheets must be destroyed */
- for (i = 0;
- i < psh.nPages;
- i++)
+ if (psh.phpage[i] != NULL)
{
- if (psh.phpage[i] != NULL)
- {
- pDestroyPropertySheetPage(psh.phpage[i]);
- }
+ pDestroyPropertySheetPage(psh.phpage[i]);
}
}
-
- HeapFree(GetProcessHeap(),
- 0,
- psh.phpage);
}
HeapFree(GetProcessHeap(),
0,
+ psh.phpage);
+
+ HeapFree(GetProcessHeap(),
+ 0,
DevAdvPropInfo);
if (hMachine != NULL)
--- trunk/reactos/lib/devmgr/misc.c 2005-12-01 15:37:00 UTC (rev 19797)
+++ trunk/reactos/lib/devmgr/misc.c 2005-12-01 16:02:15 UTC (rev 19798)
@@ -439,22 +439,11 @@
UINT MessageId = IDS_UNKNOWN;
BOOL Ret = FALSE;
- if (hMachine != NULL)
- {
- cr = CM_Get_DevNode_Status_Ex(&Status,
- &ProblemNumber,
- DevInst,
- 0,
- hMachine);
- }
- else
- {
- cr = CM_Get_DevNode_Status(&Status,
- &ProblemNumber,
- DevInst,
- 0);
- }
-
+ cr = CM_Get_DevNode_Status_Ex(&Status,
+ &ProblemNumber,
+ DevInst,
+ 0,
+ hMachine);
if (cr == CR_SUCCESS)
{
if (ProblemNumber < sizeof(ProblemStringId) / sizeof(ProblemStringId[0]))
@@ -516,25 +505,62 @@
ULONG Status, ProblemNumber;
BOOL Ret = FALSE;
- if (hMachine != NULL)
+ cr = CM_Get_DevNode_Status_Ex(&Status,
+ &ProblemNumber,
+ DevInst,
+ 0,
+ hMachine);
+ if (cr == CR_SUCCESS)
{
- cr = CM_Get_DevNode_Status_Ex(&Status,
- &ProblemNumber,
- DevInst,
- 0,
- hMachine);
+ *IsHidden = ((Status & DN_NO_SHOW_IN_DM) != 0);
+ Ret = TRUE;
}
- else
+
+ return Ret;
+}
+
+
+BOOL
+CanDisableDevice(IN DEVINST DevInst,
+ IN HANDLE hMachine,
+ OUT BOOL *CanDisable)
+{
+ CONFIGRET cr;
+ ULONG Status, ProblemNumber;
+ BOOL Ret = FALSE;
+
+ cr = CM_Get_DevNode_Status_Ex(&Status,
+ &ProblemNumber,
+ DevInst,
+ 0,
+ hMachine);
+ if (cr == CR_SUCCESS)
{
- cr = CM_Get_DevNode_Status(&Status,
- &ProblemNumber,
- DevInst,
- 0);
+ *CanDisable = ((Status & DN_DISABLEABLE) != 0);
+ Ret = TRUE;
}
+ return Ret;
+}
+
+
+BOOL
+IsDeviceEnabled(IN DEVINST DevInst,
+ IN HANDLE hMachine,
+ OUT BOOL *IsEnabled)
+{
+ CONFIGRET cr;
+ ULONG Status, ProblemNumber;
+ BOOL Ret = FALSE;
+
+ cr = CM_Get_DevNode_Status_Ex(&Status,
+ &ProblemNumber,
+ DevInst,
+ 0,
+ hMachine);
if (cr == CR_SUCCESS)
{
- *IsHidden = ((Status & DN_NO_SHOW_IN_DM) != 0);
+ *IsEnabled = ((Status & DN_STARTED) != 0);
Ret = TRUE;
}
@@ -605,7 +631,7 @@
{
szBuffer[0] = L'\0';
if (LoadString(hDllInstance,
- IDS_UNKNOWN,
+ IDS_UNKNOWNDEVICE,
szBuffer,
BufferSize))
{