📄 hwpage.c
字号:
/*
* ReactOS Device Manager Applet
* Copyright (C) 2004 - 2005 ReactOS Team
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Id: hwpage.c 22415 2006-06-19 13:27:06Z gedmurphy $
*
* PROJECT: ReactOS devmgr.dll
* FILE: lib/devmgr/hwpage.c
* PURPOSE: ReactOS Device Manager
* PROGRAMMER: Thomas Weidenmueller <w3seek@reactos.com>
* UPDATE HISTORY:
* 04-04-2004 Created
*/
#include <precomp.h>
#define NDEBUG
#include <debug.h>
typedef struct _HWDEVINFO
{
struct _HWCLASSDEVINFO *ClassDevInfo;
SP_DEVINFO_DATA DevInfoData;
BOOL HideDevice;
} HWDEVINFO, *PHWDEVINFO;
typedef struct _HWCLASSDEVINFO
{
GUID Guid;
HDEVINFO hDevInfo;
INT ImageIndex;
INT ItemCount;
PHWDEVINFO HwDevInfo;
} HWCLASSDEVINFO, *PHWCLASSDEVINFO;
typedef struct _HARDWARE_PAGE_DATA
{
HWND hWnd;
HWND hWndDevList;
HINSTANCE hComCtl32; /* only save this to keep track of the references */
INT DevListViewHeight;
SP_CLASSIMAGELIST_DATA ClassImageListData;
HWPAGE_DISPLAYMODE DisplayMode;
/* parent window subclass info */
WNDPROC ParentOldWndProc;
HWND hWndParent;
UINT NumberOfGuids;
HWCLASSDEVINFO ClassDevInfo[1];
/* struct may be dynamically expanded here! */
} HARDWARE_PAGE_DATA, *PHARDWARE_PAGE_DATA;
#define CX_TYPECOLUMN_WIDTH 80
static VOID
InitializeDevicesList(IN PHARDWARE_PAGE_DATA hpd)
{
LVCOLUMN lvc;
RECT rcClient;
WCHAR szColName[255];
int iCol = 0;
/* set the list view style */
(void)ListView_SetExtendedListViewStyle(hpd->hWndDevList,
LVS_EX_FULLROWSELECT);
/* set the list view image list */
if (hpd->ClassImageListData.ImageList != NULL)
{
(void)ListView_SetImageList(hpd->hWndDevList,
hpd->ClassImageListData.ImageList,
LVSIL_SMALL);
}
GetClientRect(hpd->hWndDevList,
&rcClient);
/* add the list view columns */
lvc.mask = LVCF_TEXT | LVCF_WIDTH;
lvc.fmt = LVCFMT_LEFT;
lvc.pszText = szColName;
if (LoadString(hDllInstance,
IDS_NAME,
szColName,
sizeof(szColName) / sizeof(szColName[0])))
{
lvc.cx = rcClient.right - CX_TYPECOLUMN_WIDTH -
GetSystemMetrics(SM_CXVSCROLL);
(void)ListView_InsertColumn(hpd->hWndDevList,
iCol++,
&lvc);
}
if (LoadString(hDllInstance,
IDS_TYPE,
szColName,
sizeof(szColName) / sizeof(szColName[0])))
{
lvc.cx = CX_TYPECOLUMN_WIDTH;
(void)ListView_InsertColumn(hpd->hWndDevList,
iCol++,
&lvc);
}
}
static BOOL
DisplaySelectedDeviceProperties(IN PHARDWARE_PAGE_DATA hpd)
{
PHWDEVINFO HwDevInfo;
SP_DEVINFO_DATA DevInfoData;
BOOL Ret = FALSE;
HwDevInfo = (PHWDEVINFO)ListViewGetSelectedItemData(hpd->hWndDevList);
if (HwDevInfo != NULL)
{
/* make a copy of the SP_DEVINFO_DATA structure on the stack, it may
become invalid in case the devices are updated */
DevInfoData = HwDevInfo->DevInfoData;
/* display the advanced properties */
Ret = DisplayDeviceAdvancedProperties(hpd->hWnd,
NULL,
HwDevInfo->ClassDevInfo->hDevInfo,
&DevInfoData,
hpd->hComCtl32,
NULL,
0) != -1;
}
return Ret;
}
static VOID
UpdateControlStates(IN PHARDWARE_PAGE_DATA hpd)
{
PHWDEVINFO HwDevInfo;
HWND hBtnTroubleShoot, hBtnProperties;
hBtnTroubleShoot = GetDlgItem(hpd->hWnd,
IDC_TROUBLESHOOT);
hBtnProperties = GetDlgItem(hpd->hWnd,
IDC_PROPERTIES);
HwDevInfo = (PHWDEVINFO)ListViewGetSelectedItemData(hpd->hWndDevList);
if (HwDevInfo != NULL)
{
/* update static controls */
WCHAR szBuffer[256];
LPWSTR szFormatted = NULL;
/* get the manufacturer string */
if (GetDeviceManufacturerString(HwDevInfo->ClassDevInfo->hDevInfo,
&HwDevInfo->DevInfoData,
szBuffer,
sizeof(szBuffer) / sizeof(szBuffer[0])) &&
LoadAndFormatString(hDllInstance,
IDS_MANUFACTURER,
&szFormatted,
szBuffer) != 0)
{
SetDlgItemText(hpd->hWnd,
IDC_MANUFACTURER,
szFormatted);
LocalFree((HLOCAL)szFormatted);
}
/* get the location string */
if (GetDeviceLocationString(HwDevInfo->DevInfoData.DevInst,
0,
szBuffer,
sizeof(szBuffer) / sizeof(szBuffer[0])) &&
LoadAndFormatString(hDllInstance,
IDS_LOCATION,
&szFormatted,
szBuffer) != 0)
{
SetDlgItemText(hpd->hWnd,
IDC_LOCATION,
szFormatted);
LocalFree((HLOCAL)szFormatted);
}
if (GetDeviceStatusString(HwDevInfo->DevInfoData.DevInst,
NULL,
szBuffer,
sizeof(szBuffer) / sizeof(szBuffer[0])) &&
LoadAndFormatString(hDllInstance,
IDS_STATUS,
&szFormatted,
szBuffer) != 0)
{
SetDlgItemText(hpd->hWnd,
IDC_STATUS,
szFormatted);
LocalFree((HLOCAL)szFormatted);
}
}
else
{
/* 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(hBtnProperties,
HwDevInfo != 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 and structures */
while (ClassDevInfo != LastClassDevInfo)
{
if (ClassDevInfo->hDevInfo != INVALID_HANDLE_VALUE)
{
SetupDiDestroyDeviceInfoList(ClassDevInfo->hDevInfo);
ClassDevInfo->hDevInfo = INVALID_HANDLE_VALUE;
}
ClassDevInfo->ItemCount = 0;
ClassDevInfo->ImageIndex = 0;
if (ClassDevInfo->HwDevInfo != NULL)
{
HeapFree(GetProcessHeap(),
0,
ClassDevInfo->HwDevInfo);
ClassDevInfo->HwDevInfo = NULL;
}
ClassDevInfo++;
}
}
static VOID
BuildDevicesList(IN PHARDWARE_PAGE_DATA hpd)
{
PHWCLASSDEVINFO ClassDevInfo, LastClassDevInfo;
SP_DEVINFO_DATA DevInfoData;
DevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
ClassDevInfo = hpd->ClassDevInfo;
LastClassDevInfo = ClassDevInfo + hpd->NumberOfGuids;
while (ClassDevInfo != LastClassDevInfo)
{
ClassDevInfo->ImageIndex = -1;
/* open a class device handle for the GUID we're processing */
ClassDevInfo->hDevInfo = SetupDiGetClassDevs(&ClassDevInfo->Guid,
NULL,
hpd->hWnd,
DIGCF_PRESENT | DIGCF_PROFILE);
if (ClassDevInfo->hDevInfo != INVALID_HANDLE_VALUE)
{
DWORD MemberIndex = 0;
SetupDiGetClassImageIndex(&hpd->ClassImageListData,
&ClassDevInfo->Guid,
&ClassDevInfo->ImageIndex);
/* enumerate all devices in the class */
while (SetupDiEnumDeviceInfo(ClassDevInfo->hDevInfo,
MemberIndex++,
&DevInfoData))
{
BOOL HideDevice = FALSE;
if (ClassDevInfo->HwDevInfo != NULL)
{
PHWDEVINFO HwNewDevInfo = HeapReAlloc(GetProcessHeap(),
0,
ClassDevInfo->HwDevInfo,
(ClassDevInfo->ItemCount + 1) *
sizeof(HWDEVINFO));
if (HwNewDevInfo != NULL)
{
ClassDevInfo->HwDevInfo = HwNewDevInfo;
}
else
{
DPRINT1("Unable to allocate memory for %d SP_DEVINFO_DATA structures!\n",
ClassDevInfo->ItemCount + 1);
break;
}
}
else
{
ClassDevInfo->HwDevInfo = HeapAlloc(GetProcessHeap(),
0,
sizeof(HWDEVINFO));
if (ClassDevInfo->HwDevInfo == NULL)
{
DPRINT1("Unable to allocate memory for a SP_DEVINFO_DATA structures!\n");
break;
}
}
/* Find out if the device should be hidden by default */
IsDeviceHidden(DevInfoData.DevInst,
NULL,
&HideDevice);
/* save all information for the current device */
ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount].ClassDevInfo = ClassDevInfo;
ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount].DevInfoData = DevInfoData;
ClassDevInfo->HwDevInfo[ClassDevInfo->ItemCount++].HideDevice = HideDevice;
}
}
ClassDevInfo++;
}
}
static BOOL
DeviceIdMatch(IN HDEVINFO DeviceInfoSet,
IN PSP_DEVINFO_DATA DeviceInfoData,
IN LPCWSTR lpDeviceId)
{
DWORD DevIdLen;
LPWSTR lpQueriedDeviceId;
BOOL Ret = FALSE;
if (!SetupDiGetDeviceInstanceId(DeviceInfoSet,
DeviceInfoData,
NULL,
0,
&DevIdLen) &&
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
if (DevIdLen == wcslen(lpDeviceId) + 1)
{
lpQueriedDeviceId = HeapAlloc(GetProcessHeap(),
0,
DevIdLen * sizeof(WCHAR));
if (lpQueriedDeviceId != NULL)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -