📄 hclient.c
字号:
PostMessage(hDlg,
WM_COMMAND,
IDC_TYPE + (CBN_SELCHANGE<<16),
(LPARAM) GetDlgItem(hDlg,IDC_TYPE));
break;
}
break;
//
// On a type change, retrieve the currently active device
// from the IDC_DEVICES box and display the data that
// corresponds to the item just selected
//
case IDC_TYPE:
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
GET_CURRENT_DEVICE(hDlg, pDevice);
SendDlgItemMessage(hDlg,
IDC_ITEMS,
LB_RESETCONTENT,
0,
0);
SendDlgItemMessage(hDlg,
IDC_ATTRIBUTES,
LB_RESETCONTENT,
0,
0);
if (NULL != pDevice)
{
iIndex = (INT) SendDlgItemMessage(hDlg,
IDC_TYPE,
CB_GETCURSEL,
0,
0);
iItemType = (INT) SendDlgItemMessage(hDlg,
IDC_TYPE,
CB_GETITEMDATA,
iIndex,
0);
switch(iItemType)
{
case INPUT_BUTTON:
vDisplayInputButtons(pDevice,GetDlgItem(hDlg,IDC_ITEMS));
break;
case INPUT_VALUE:
vDisplayInputValues(pDevice,GetDlgItem(hDlg,IDC_ITEMS));
break;
case OUTPUT_BUTTON:
vDisplayOutputButtons(pDevice,GetDlgItem(hDlg,IDC_ITEMS));
break;
case OUTPUT_VALUE:
vDisplayOutputValues(pDevice,GetDlgItem(hDlg,IDC_ITEMS));
break;
case FEATURE_BUTTON:
vDisplayFeatureButtons(pDevice,GetDlgItem(hDlg,IDC_ITEMS));
break;
case FEATURE_VALUE:
vDisplayFeatureValues(pDevice,GetDlgItem(hDlg,IDC_ITEMS));
break;
}
PostMessage(hDlg,
WM_COMMAND,
IDC_ITEMS + (LBN_SELCHANGE << 16),
(LPARAM) GetDlgItem(hDlg,IDC_ITEMS));
}
break; // case CBN_SELCHANGE
} //end switch HIWORD wParam
break; //case IDC_TYPE control
case IDC_ITEMS:
switch(HIWORD(wParam))
{
case LBN_SELCHANGE:
iItemType = 0;
iIndex = (INT) SendDlgItemMessage(hDlg,
IDC_TYPE,
CB_GETCURSEL,
0,
0);
if (-1 != iIndex)
{
iItemType = (INT) SendDlgItemMessage(hDlg,
IDC_TYPE,
CB_GETITEMDATA,
iIndex,
0);
}
iIndex = (INT) SendDlgItemMessage(hDlg,
IDC_ITEMS,
LB_GETCURSEL,
0,
0);
switch (iItemType)
{
case INPUT_BUTTON:
case OUTPUT_BUTTON:
case FEATURE_BUTTON:
pButtonCaps = NULL;
if (-1 != iIndex)
{
pButtonCaps = (PHIDP_BUTTON_CAPS) SendDlgItemMessage(hDlg,
IDC_ITEMS,
LB_GETITEMDATA,
iIndex,
0);
}
SendDlgItemMessage(hDlg, IDC_ATTRIBUTES, LB_RESETCONTENT, 0, 0);
if (NULL != pButtonCaps)
{
vDisplayButtonAttributes(pButtonCaps, GetDlgItem(hDlg,IDC_ATTRIBUTES));
}
break;
case INPUT_VALUE:
case OUTPUT_VALUE:
case FEATURE_VALUE:
pValueCaps = NULL;
if (-1 != iIndex)
{
pValueCaps = (PHIDP_VALUE_CAPS) SendDlgItemMessage(hDlg,
IDC_ITEMS,
LB_GETITEMDATA,
iIndex,
0);
}
SendDlgItemMessage(hDlg, IDC_ATTRIBUTES, LB_RESETCONTENT, 0, 0);
if (NULL != pValueCaps)
{
vDisplayValueAttributes(pValueCaps,GetDlgItem(hDlg,IDC_ATTRIBUTES));
}
break;
case HID_CAPS:
GET_CURRENT_DEVICE(hDlg, pDevice);
if (NULL != pDevice)
{
vDisplayDeviceCaps(&(pDevice -> Caps),GetDlgItem(hDlg,IDC_ATTRIBUTES));
}
break;
case DEVICE_ATTRIBUTES:
GET_CURRENT_DEVICE(hDlg, pDevice);
if (NULL != pDevice)
{
SendDlgItemMessage(hDlg, IDC_ATTRIBUTES, LB_RESETCONTENT, 0, 0);
vDisplayDeviceAttributes(&(pDevice -> Attributes) ,GetDlgItem(hDlg,IDC_ATTRIBUTES));
}
break;
} //end switch iItemType//
break; //end case LBN_SELCHANGE in IDC_ITEMS//
} //end switch HIWORD wParam//
break; //case IDC_ITEMS//
case IDC_ABOUT:
MessageBox(hDlg,
"Sample HID client Application. Microsoft Corp \nCopyright (C) 1997",
"About HClient",
MB_ICONINFORMATION);
break;
case IDOK:
case IDCANCEL:
//
// Destroy the physical device list for exit
//
DestroyListWithCallback(&PhysicalDeviceList, DestroyDeviceListCallback);
EndDialog(hDlg,0);
break;
} //end switch wParam//
break;
//
// For a device change message, we are only concerned about the
// DBT_DEVICEREMOVECOMPLETE and DBT_DEVICEARRIVAL events. I have
// yet to determine how to process the device change message
// only for HID devices. Therefore, there are two problems
// with the below implementation. First of all, we must reload
// the device list any time a device is added to the system.
// Secondly, at least two DEVICEARRIVAL messages are received
// per HID. One corresponds to the physical device. The second
// change and any more correspond to each collection on the
// physical device so a system that has one HID device with
// two top level collections (a keyboard and a mouse) will receive
// three DEVICEARRIVAL/REMOVALs causing the program to reload it's
// device list more than once.
//
//
// To handle dynamic changing of devices, we have already registered
// notification for both HID class changes and for notification
// for our open file objects. Since we are only concerned about
// arrival/removal of devices, we only need to process those wParam.
// lParam points to some sort of DEV_BROADCAST_HDR struct. For device
// arrival, we only deal with the message if that struct is a
// DEV_BROADCAST_DEVICEINTERFACE structure. For device removal, we're
// only concerned if the struct is a DEV_BROADCAST_HANDLE structure.
//
case WM_DEVICECHANGE:
switch (wParam)
{
PDEV_BROADCAST_HDR broadcastHdr;
case DBT_DEVICEARRIVAL:
broadcastHdr = (PDEV_BROADCAST_HDR) lParam;
if (DBT_DEVTYP_DEVICEINTERFACE == broadcastHdr -> dbch_devicetype)
{
PDEV_BROADCAST_DEVICEINTERFACE pbroadcastInterface;
PDEVICE_LIST_NODE currNode, lastNode;
pbroadcastInterface = (PDEV_BROADCAST_DEVICEINTERFACE) lParam;
//
// Search for a previous instance of this device
// in the device list...In some cases, multiple
// messages are received for the same device. We
// obviously only want one instance of the device
// showing up in the dialog box.
//
if (!IsListEmpty(&PhysicalDeviceList))
{
currNode = (PDEVICE_LIST_NODE) GetListHead(&PhysicalDeviceList);
lastNode = (PDEVICE_LIST_NODE) GetListTail(&PhysicalDeviceList);
//
// This loop should always terminate since the device
// handle should be somewhere in the physical device list
//
while (1)
{
if (0 == strcmp(currNode -> HidDeviceInfo.DevicePath,
pbroadcastInterface -> dbcc_name))
{
return (TRUE);
}
if (currNode == lastNode)
{
break;
}
currNode = (PDEVICE_LIST_NODE) GetNextEntry(currNode);
}
}
//
// In this structure, we are given the name of the device
// to open. So all that needs to be done is open
// a new hid device with the string
//
listNode = (PDEVICE_LIST_NODE) malloc(sizeof(DEVICE_LIST_NODE));
if (NULL == listNode)
{
MessageBox(hDlg,
"Error -- Couldn't allocate memory for new device list node",
HCLIENT_ERROR,
MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL);
break;
}
//
// Open the hid device for query access
//
if (!OpenHidDevice (pbroadcastInterface -> dbcc_name,
FALSE,
FALSE,
FALSE,
FALSE,
&(listNode -> HidDeviceInfo)))
{
MessageBox(hDlg,
"Error -- Couldn't open HID device",
HCLIENT_ERROR,
MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL);
free(listNode);
break;
}
if (!RegisterHidDevice(hDlg, listNode))
{
MessageBox(hDlg,
"Error -- Couldn't register handle notification",
HCLIENT_ERROR,
MB_ICONEXCLAMATION | MB_OK | MB_TASKMODAL);
CloseHidDevice(&(listNode -> HidDeviceInfo));
free(listNode);
break;
}
listNode -> DeviceOpened = TRUE;
InsertTail(&PhysicalDeviceList, listNode);
vLoadDevices(GetDlgItem(hDlg,IDC_DEVICES));
PostMessage(hDlg,
WM_COMMAND,
IDC_DEVICES + (CBN_SELCHANGE << 16),
(LPARAM) GetDlgItem(hDlg,IDC_DEVICES));
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -