📄 hwpage.c
字号:
if (SetupDiGetDeviceInstanceId(DeviceInfoSet,
DeviceInfoData,
lpQueriedDeviceId,
DevIdLen,
NULL))
{
Ret = (wcscmp(lpDeviceId,
lpQueriedDeviceId) == 0);
}
HeapFree(GetProcessHeap(),
0,
lpQueriedDeviceId);
}
}
}
return Ret;
}
static VOID
FillDevicesListViewControl(IN PHARDWARE_PAGE_DATA hpd,
IN LPCWSTR lpSelectDeviceId OPTIONAL,
IN GUID *SelectedClassGuid OPTIONAL)
{
PHWCLASSDEVINFO ClassDevInfo, LastClassDevInfo;
PHWDEVINFO HwDevInfo, LastHwDevInfo;
WCHAR szBuffer[255];
BOOL SelectedInClass;
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;
SelectedInClass = (SelectedClassGuid != NULL &&
IsEqualGUID(SelectedClassGuid,
&ClassDevInfo->Guid));
while (HwDevInfo != LastHwDevInfo)
{
INT iItem;
LVITEM li = {0};
/* get the device name */
if (!HwDevInfo->HideDevice &&
GetDeviceDescriptionString(ClassDevInfo->hDevInfo,
&HwDevInfo->DevInfoData,
szBuffer,
sizeof(szBuffer) / sizeof(szBuffer[0])))
{
li.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT | LVIF_IMAGE;
li.iItem = ItemCount;
if ((ItemCount == 0 && lpSelectDeviceId == NULL) ||
(SelectedInClass &&
DeviceIdMatch(ClassDevInfo->hDevInfo,
&HwDevInfo->DevInfoData,
lpSelectDeviceId)))
{
li.state = LVIS_SELECTED;
}
li.stateMask = LVIS_SELECTED;
li.pszText = szBuffer;
li.iImage = ClassDevInfo->ImageIndex;
li.lParam = (LPARAM)HwDevInfo;
iItem = ListView_InsertItem(hpd->hWndDevList,
&li);
if (iItem != -1)
{
ItemCount++;
/* get the device type for the second column */
if (GetDeviceTypeString(&HwDevInfo->DevInfoData,
szBuffer,
sizeof(szBuffer) / sizeof(szBuffer[0])))
{
li.mask = LVIF_TEXT;
li.iItem = iItem;
li.iSubItem = 1;
(void)ListView_SetItem(hpd->hWndDevList,
&li);
}
}
}
HwDevInfo++;
}
}
ClassDevInfo++;
}
/* update the controls */
UpdateControlStates(hpd);
}
static VOID
UpdateDevicesListViewControl(IN PHARDWARE_PAGE_DATA hpd)
{
PHWDEVINFO HwDevInfo;
GUID SelectedClassGuid = {0};
LPWSTR lpDeviceId = NULL;
/* if a device currently is selected, remember the device id so we can
select the device after the update if still present */
HwDevInfo = (PHWDEVINFO)ListViewGetSelectedItemData(hpd->hWndDevList);
if (HwDevInfo != NULL)
{
DWORD DevIdLen;
if (!SetupDiGetDeviceInstanceId(HwDevInfo->ClassDevInfo->hDevInfo,
&HwDevInfo->DevInfoData,
NULL,
0,
&DevIdLen) &&
GetLastError() == ERROR_INSUFFICIENT_BUFFER)
{
SelectedClassGuid = HwDevInfo->DevInfoData.ClassGuid;
lpDeviceId = HeapAlloc(GetProcessHeap(),
0,
DevIdLen * sizeof(WCHAR));
if (lpDeviceId != NULL &&
!SetupDiGetDeviceInstanceId(HwDevInfo->ClassDevInfo->hDevInfo,
&HwDevInfo->DevInfoData,
lpDeviceId,
DevIdLen,
NULL))
{
HeapFree(GetProcessHeap(),
0,
lpDeviceId);
lpDeviceId = NULL;
}
}
}
/* clear the devices list view control */
(void)ListView_DeleteAllItems(hpd->hWndDevList);
/* free the device list */
FreeDevicesList(hpd);
/* build rebuild the device list and fill the list box again */
FillDevicesListViewControl(hpd,
lpDeviceId,
(lpDeviceId != NULL ?
&SelectedClassGuid :
NULL));
if (lpDeviceId != NULL)
{
HeapFree(GetProcessHeap(),
0,
lpDeviceId);
}
}
static LRESULT
CALLBACK
ParentSubWndProc(IN HWND hwnd,
IN UINT uMsg,
IN WPARAM wParam,
IN LPARAM lParam)
{
PHARDWARE_PAGE_DATA hpd;
hpd = (PHARDWARE_PAGE_DATA)GetProp(hwnd,
L"DevMgrSubClassInfo");
if (hpd != NULL)
{
if (uMsg == WM_SIZE)
{
/* resize the hardware page */
SetWindowPos(hpd->hWnd,
NULL,
0,
0,
LOWORD(lParam),
HIWORD(lParam),
SWP_NOZORDER);
}
else if (uMsg == WM_DEVICECHANGE && IsWindowVisible(hpd->hWnd))
{
/* forward a WM_DEVICECHANGE message to the hardware
page which wouldn't get the message itself as it is
a child window */
SendMessage(hpd->hWnd,
WM_DEVICECHANGE,
wParam,
lParam);
}
/* pass the message the the old window proc */
return CallWindowProc(hpd->ParentOldWndProc,
hwnd,
uMsg,
wParam,
lParam);
}
else
{
/* this is not a good idea if the subclassed window was an ansi
window, but we failed finding out the previous window proc
so we can't use CallWindowProc. This should rarely - if ever -
happen. */
return DefWindowProc(hwnd,
uMsg,
wParam,
lParam);
}
}
static VOID
HardwareDlgResize(IN PHARDWARE_PAGE_DATA hpd,
IN INT cx,
IN INT cy)
{
HDWP dwp;
HWND hControl, hButton;
INT Width, x, y;
RECT rc, rcButton;
POINT pt = {0};
POINT ptMargin = {0};
POINT ptMarginGroup = {0};
/* use left margin of the IDC_DEVICES label as the right
margin of all controls outside the group box */
hControl = GetDlgItem(hpd->hWnd,
IDC_DEVICES);
GetWindowRect(hControl,
&rc);
MapWindowPoints(hControl,
hpd->hWnd,
&ptMargin,
1);
Width = cx - (2 * ptMargin.x);
if ((dwp = BeginDeferWindowPos(8)))
{
/* rc already has the window rect of IDC_DEVICES! */
if (!(dwp = DeferWindowPos(dwp,
hControl,
NULL,
0,
0,
Width,
rc.bottom - rc.top,
SWP_NOMOVE | SWP_NOZORDER)))
{
return;
}
/* resize the devices list view control */
GetWindowRect(hpd->hWndDevList,
&rc);
MapWindowPoints(hpd->hWndDevList,
hpd->hWnd,
&pt,
1);
y = pt.y + hpd->DevListViewHeight + ptMargin.y;
if (!(dwp = DeferWindowPos(dwp,
hpd->hWndDevList,
NULL,
0,
0,
Width,
hpd->DevListViewHeight,
SWP_NOMOVE | SWP_NOZORDER)))
{
return;
}
/* resize the group box control */
hControl = GetDlgItem(hpd->hWnd,
IDC_PROPERTIESGROUP);
GetWindowRect(hControl,
&rc);
if (!(dwp = DeferWindowPos(dwp,
hControl,
NULL,
ptMargin.x,
y,
Width,
cy - y - ptMargin.y,
SWP_NOZORDER)))
{
return;
}
/* use left margin of the IDC_MANUFACTURER label as the right
margin of all controls inside the group box */
hControl = GetDlgItem(hpd->hWnd,
IDC_MANUFACTURER);
GetWindowRect(hControl,
&rc);
MapWindowPoints(hControl,
hpd->hWnd,
&ptMarginGroup,
1);
ptMarginGroup.y = ptMargin.y * 2;
Width = cx - (2 * ptMarginGroup.x);
y += ptMarginGroup.y;
if (!(dwp = DeferWindowPos(dwp,
hControl,
NULL,
ptMarginGroup.x,
y,
Width,
rc.bottom - rc.top,
SWP_NOZORDER)))
{
return;
}
y += rc.bottom - rc.top + (ptMargin.y / 2);
/* resize the IDC_LOCATION label */
hControl = GetDlgItem(hpd->hWnd,
IDC_LOCATION);
GetWindowRect(hControl,
&rc);
if (!(dwp = DeferWindowPos(dwp,
hControl,
NULL,
ptMarginGroup.x,
y,
Width,
rc.bottom - rc.top,
SWP_NOZORDER)))
{
return;
}
y += rc.bottom - rc.top + (ptMargin.y / 2);
/* measure the size of the buttons */
hButton = GetDlgItem(hpd->hWnd,
IDC_PROPERTIES);
GetWindowRect(hButton,
&rcButton);
/* resize the IDC_STATUS label */
hControl = GetDlgItem(hpd->hWnd,
IDC_STATUS);
GetWindowRect(hControl,
&rc);
if (!(dwp = DeferWindowPos(dwp,
hControl,
NULL,
ptMarginGroup.x,
y,
Width,
cy - y - (3 * ptMargin.y) -
(rcButton.bottom - rcButton.top),
SWP_NOZORDER)))
{
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -