--- trunk/reactos/lib/devmgr/hwpage.c 2005-11-25 23:16:28 UTC (rev 19591)
+++ trunk/reactos/lib/devmgr/hwpage.c 2005-11-25 23:36:32 UTC (rev 19592)
@@ -49,6 +49,7 @@
{
GUID Guid;
HDEVINFO hDevInfo;
+ INT ImageIndex;
INT ItemCount;
PHWDEVINFO HwDevInfo;
} HWCLASSDEVINFO, *PHWCLASSDEVINFO;
@@ -129,98 +130,203 @@
UpdateControlStates(IN PHARDWARE_PAGE_DATA hpd)
{
PHWDEVINFO HwDevInfo;
+ HWND hBtnTroubleShoot, hBtnProperties;
+ DWORD RegDataType;
+
+ hBtnTroubleShoot = GetDlgItem(hpd->hWnd,
+ IDC_TROUBLESHOOT);
+ hBtnProperties = GetDlgItem(hpd->hWnd,
+ IDC_PROPERTIES);
HwDevInfo = (PHWDEVINFO)ListViewGetSelectedItemData(hpd->hWndDevList);
if (HwDevInfo != NULL)
{
- /* FIXME - update static controls and enable buttons */
+ /* update static controls */
+ WCHAR szBuffer[256];
+ LPWSTR szFormatted = NULL;
+
+ if (!SetupDiGetDeviceRegistryProperty(HwDevInfo->ClassDevInfo->hDevInfo,
+ &HwDevInfo->DevInfoData,
+ SPDRP_MFG,
+ &RegDataType,
+ (PBYTE)szBuffer,
+ sizeof(szBuffer),
+ NULL) ||
+ RegDataType != REG_SZ)
+ {
+ /* FIXME - check string for NULL termination! */
+ szBuffer[0] = L'\0';
+ }
+ if (LoadAndFormatString(hDllInstance,
+ IDS_MANUFACTURER,
+ &szFormatted,
+ szBuffer) != 0)
+ {
+ SetDlgItemText(hpd->hWnd,
+ IDC_MANUFACTURER,
+ szFormatted);
+ LocalFree((HLOCAL)szFormatted);
+ }
+
+ /* FIXME - Display location and status */
}
else
{
- /* FIXME - clear static controls and disable buttons */
+ /* clear static controls */
+ SetDlgItemText(hpd->hWnd,
+ IDC_MANUFACTURER,
+ NULL);
+ SetDlgItemText(hpd->hWnd,
+ IDC_LOCATION,
+ NULL);
+ SetDlgItemText(hpd->hWnd,
+ IDC_STATUS,
+ NULL);
}
+
+ EnableWindow(hBtnTroubleShoot,
+ HwDevInfo != NULL);
+ EnableWindow(hBtnTroubleShoot,
+ hBtnProperties != NULL);
}
+static VOID
+FreeDevicesList(IN PHARDWARE_PAGE_DATA hpd)
+{
+ PHWCLASSDEVINFO ClassDevInfo, LastClassDevInfo;
+ ClassDevInfo = hpd->ClassDevInfo;
+ LastClassDevInfo = ClassDevInfo + hpd->NumberOfGuids;
+
+ /* free the device info set handles */
+ while (ClassDevInfo != LastClassDevInfo)
+ {
+ if (ClassDevInfo->hDevInfo != INVALID_HANDLE_VALUE)
+ {
+ SetupDiDestroyDeviceInfoList(ClassDevInfo->hDevInfo);
+ }
+ ClassDevInfo->hDevInfo = NULL;
+ ClassDevInfo->ItemCount = 0;
+ ClassDevInfo->ImageIndex = 0;
+
+ if (ClassDevInfo->HwDevInfo != NULL)
+ {
+ HeapFree(GetProcessHeap(),
+ 0,
+ ClassDevInfo->HwDevInfo);
+ ClassDevInfo->HwDevInfo = NULL;
+ }
+
+ ClassDevInfo++;
+ }
+}
+
+
static VOID
-FillDevicesList(IN PHARDWARE_PAGE_DATA hpd)
+BuildDevicesList(IN PHARDWARE_PAGE_DATA hpd)
{
- PHWCLASSDEVINFO DevInfo, LastDevInfo;
+ PHWCLASSDEVINFO ClassDevInfo, LastClassDevInfo;
SP_DEVINFO_DATA DevInfoData;
- WCHAR szBuffer[255];
- INT ItemCount = 0;
DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
- DevInfo = hpd->ClassDevInfo;
- LastDevInfo = DevInfo + hpd->NumberOfGuids;
+ ClassDevInfo = hpd->ClassDevInfo;
+ LastClassDevInfo = ClassDevInfo + hpd->NumberOfGuids;
- while (DevInfo != LastDevInfo)
+ while (ClassDevInfo != LastClassDevInfo)
{
- INT ImageIndex = -1;
-
- DevInfo->hDevInfo = SetupDiGetClassDevs(&DevInfo->Guid,
- NULL,
- hpd->hWnd,
- DIGCF_PRESENT);
- if (DevInfo->hDevInfo != INVALID_HANDLE_VALUE)
+ ClassDevInfo->ImageIndex = -1;
+ ClassDevInfo->hDevInfo = SetupDiGetClassDevs(&ClassDevInfo->Guid,
+ NULL,
+ hpd->hWnd,
+ DIGCF_PRESENT);
+ if (ClassDevInfo->hDevInfo != INVALID_HANDLE_VALUE)
{
- LVITEM li;
DWORD MemberIndex = 0;
SetupDiGetClassImageIndex(&hpd->ClassImageListData,
- &DevInfo->Guid,
- &ImageIndex);
+ &ClassDevInfo->Guid,
+ &ClassDevInfo->ImageIndex);
- while (SetupDiEnumDeviceInfo(DevInfo->hDevInfo,
+ while (SetupDiEnumDeviceInfo(ClassDevInfo->hDevInfo,
MemberIndex++,
&DevInfoData))
{
- DWORD RegDataType;
- INT iItem;
-
- if (DevInfo->HwDevInfo != NULL)
+ if (ClassDevInfo->HwDevInfo != NULL)
{
PHWDEVINFO HwNewDevInfo = HeapReAlloc(GetProcessHeap(),
0,
- DevInfo->HwDevInfo,
- (DevInfo->ItemCount + 1) *
+ ClassDevInfo->HwDevInfo,
+ (ClassDevInfo->ItemCount + 1) *
sizeof(HWDEVINFO));
if (HwNewDevInfo != NULL)
{
- DevInfo->HwDevInfo = HwNewDevInfo;
+ ClassDevInfo->HwDevInfo = HwNewDevInfo;
}
else
{
DPRINT1("Unable to allocate memory for %d SP_DEVINFO_DATA structures!\n",
- DevInfo->ItemCount + 1);
+ ClassDevInfo->ItemCount + 1);
break;
}
}
else
{
- DevInfo->HwDevInfo = HeapAlloc(GetProcessHeap(),
- 0,
- sizeof(HWDEVINFO));
- if (DevInfo->HwDevInfo == NULL)
+ ClassDevInfo->HwDevInfo = HeapAlloc(GetProcessHeap(),
+ 0,
+ sizeof(HWDEVINFO));
+ if (ClassDevInfo->HwDevInfo == NULL)
{
DPRINT1("Unable to allocate memory for a SP_DEVINFO_DATA structures!\n");
break;
}
}
- DevInfo->HwDevInfo[DevInfo->ItemCount].ClassDevInfo = DevInfo;
- DevInfo->HwDevInfo[DevInfo->ItemCount++].DevInfoData = DevInfoData;
+ ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount].ClassDevInfo = ClassDevInfo;
+ ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount++].DevInfoData = DevInfoData;
+ }
+ }
- if ((SetupDiGetDeviceRegistryProperty(DevInfo->hDevInfo,
- &DevInfoData,
+ ClassDevInfo++;
+ }
+}
+
+
+static VOID
+FillDevicesList(IN PHARDWARE_PAGE_DATA hpd)
+{
+ PHWCLASSDEVINFO ClassDevInfo, LastClassDevInfo;
+ PHWDEVINFO HwDevInfo, LastHwDevInfo;
+ WCHAR szBuffer[255];
+ INT ItemCount = 0;
+
+ BuildDevicesList(hpd);
+
+ ClassDevInfo = hpd->ClassDevInfo;
+ LastClassDevInfo = ClassDevInfo + hpd->NumberOfGuids;
+
+ while (ClassDevInfo != LastClassDevInfo)
+ {
+ if (ClassDevInfo->HwDevInfo != NULL)
+ {
+ HwDevInfo = ClassDevInfo->HwDevInfo;
+ LastHwDevInfo = HwDevInfo + ClassDevInfo->ItemCount;
+
+ while (HwDevInfo != LastHwDevInfo)
+ {
+ DWORD RegDataType;
+ INT iItem;
+ LVITEM li;
+
+ if ((SetupDiGetDeviceRegistryProperty(ClassDevInfo->hDevInfo,
+ &HwDevInfo->DevInfoData,
SPDRP_FRIENDLYNAME,
&RegDataType,
(PBYTE)szBuffer,
sizeof(szBuffer),
NULL) ||
- SetupDiGetDeviceRegistryProperty(DevInfo->hDevInfo,
- &DevInfoData,
+ SetupDiGetDeviceRegistryProperty(ClassDevInfo->hDevInfo,
+ &HwDevInfo->DevInfoData,
SPDRP_DEVICEDESC,
&RegDataType,
(PBYTE)szBuffer,
@@ -236,8 +342,8 @@
li.state = (ItemCount == 0 ? LVIS_SELECTED : 0);
li.stateMask = LVIS_SELECTED;
li.pszText = szBuffer;
- li.iImage = ImageIndex;
- li.lParam = (LPARAM)&DevInfo->HwDevInfo[DevInfo->ItemCount - 1];
+ li.iImage = ClassDevInfo->ImageIndex;
+ li.lParam = (LPARAM)HwDevInfo;
iItem = ListView_InsertItem(hpd->hWndDevList,
&li);
@@ -245,7 +351,7 @@
{
ItemCount++;
- if (SetupDiGetClassDescription(&DevInfo->Guid,
+ if (SetupDiGetClassDescription(&ClassDevInfo->Guid,
szBuffer,
sizeof(szBuffer) / sizeof(szBuffer[0]),
NULL))
@@ -259,10 +365,12 @@
}
}
}
+
+ HwDevInfo++;
}
}
- DevInfo++;
+ ClassDevInfo++;
}
/* update the controls */
@@ -509,8 +617,6 @@
HWND hBtnTroubleShoot = GetDlgItem(hpd->hWnd,
IDC_TROUBLESHOOT);
- EnableWindow(hBtnTroubleShoot,
- Enable);
ShowWindow(hBtnTroubleShoot,
Enable ? SW_SHOW : SW_HIDE);
}
@@ -650,22 +756,9 @@
case WM_DESTROY:
{
- UINT i;
+ /* free devices list */
+ FreeDevicesList(hpd);
- /* free the device info set handles */
- for (i = 0;
- i < hpd->NumberOfGuids;
- i++)
- {
- SetupDiDestroyDeviceInfoList(hpd->ClassDevInfo[i].hDevInfo);
- if (hpd->ClassDevInfo[i].HwDevInfo != NULL)
- {
- HeapFree(GetProcessHeap(),
- 0,
- hpd->ClassDevInfo[i].HwDevInfo);
- }
- }
-
/* restore the old window proc of the subclassed parent window */
if (hpd->hWndParent != NULL && hpd->ParentOldWndProc != NULL)
{