ecdisp.c
来自「winddk src目录下的WDM源码压缩!」· C语言 代码 · 共 1,674 行 · 第 1/5 页
C
1,674 行
ReadThread = NULL;
PostMessage(hDlg,
WM_COMMAND,
IDC_EXTCALLS + (CBN_SELCHANGE << 16),
(LPARAM) GetDlgItem(hDlg,IDC_EXTCALLS));
break;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDC_EXTCALLS:
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
iIndex = (INT) SendDlgItemMessage(hDlg,
IDC_EXTCALLS,
CB_GETCURSEL,
0,
0);
vEnableParameters(hDlg,
SendDlgItemMessage(hDlg,
IDC_EXTCALLS,
CB_GETITEMDATA,
iIndex,
0));
break;
}
break;
case IDC_INPUT_SELECT:
if (CBN_SELCHANGE == HIWORD(wParam))
{
BufferDisplay_ChangeSelection(pInputDisplay);
}
break;
case IDC_OUTPUT_SELECT:
if (CBN_SELCHANGE == HIWORD(wParam))
{
BufferDisplay_ChangeSelection(pOutputDisplay);
}
break;
case IDC_FEATURE_SELECT:
if (CBN_SELCHANGE == HIWORD(wParam))
{
BufferDisplay_ChangeSelection(pFeatureDisplay);
}
break;
case IDC_EXECUTE:
/*
// Get the parameters and verify that they are all correct
// If there is an error, display an error message and
// don't continue any further.
*/
if ( !fGetAndVerifyParameters(hDlg, ¶ms) )
{
ECDISP_ERROR(hDlg, "Error: One or more parameters are invalid");
}
/*
// Else the parameters are valid and we can execute the call
*/
else
{
iIndex = (INT) SendDlgItemMessage(hDlg, IDC_EXTCALLS, CB_GETCURSEL, 0, 0);
iIndex = (INT) SendDlgItemMessage(hDlg, IDC_EXTCALLS, CB_GETITEMDATA, iIndex, 0);
/*
// Now that we know the function to execute we need to execute it
// and output the data
*/
SendDlgItemMessage(hDlg, IDC_CALLOUTPUT, LB_RESETCONTENT, 0, 0);
vExecuteAndDisplayOutput(GetDlgItem(hDlg, IDC_CALLOUTPUT), pDevice, iIndex, ¶ms);
}
break; /* end IDC_EXECUTE case */
/*
// Start up a read thread that can read input reports while
// we operate on the other stuff
*/
case IDC_READ_SYNCH:
case IDC_READ_ASYNCH:
if (NULL == ReadThread)
{
readContext.HidDevice = pDevice;
readContext.TerminateThread = FALSE;
readContext.DoOneRead = TRUE;
readContext.DisplayEvent = NULL;
readContext.DisplayWindow = hDlg;
ReadThread = CreateThread( NULL,
0,
(LOWORD(wParam) == IDC_READ_SYNCH) ?
SynchReadThreadProc :
AsynchReadThreadProc,
(LPVOID) &readContext,
0,
&threadID);
if (NULL == ReadThread)
{
MessageBox(hDlg,
"Unable to create read thread",
HCLIENT_ERROR,
MB_ICONEXCLAMATION);
}
else
{
EnableWindow(GetDlgItem(hDlg, IDC_READ_SYNCH),
(LOWORD(wParam) == IDC_READ_SYNCH));
EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH),
(LOWORD(wParam) == IDC_READ_ASYNCH));
SetWindowText(GetDlgItem(hDlg, LOWORD(wParam)),
"Stop Read Thread");
EnableWindow(GetDlgItem(hDlg, IDC_CANCEL), FALSE);
}
}
else
{
readContext.TerminateThread = TRUE;
WaitForSingleObject(ReadThread, INFINITE);
ReadThread = NULL;
SetWindowText(GetDlgItem(hDlg, IDC_READ_SYNCH),
"Start Synchronous Read Thread");
SetWindowText(GetDlgItem(hDlg, IDC_READ_ASYNCH),
"Start Asynchronous Read Thread");
EnableWindow(GetDlgItem(hDlg, IDC_READ_SYNCH), TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_READ_ASYNCH), TRUE);
EnableWindow(GetDlgItem(hDlg, IDC_CANCEL), TRUE);
}
break;
case IDC_CANCEL:
BufferDisplay_Destroy(pInputDisplay);
BufferDisplay_Destroy(pOutputDisplay);
BufferDisplay_Destroy(pFeatureDisplay);
EndDialog(hDlg, 0);
break;
}
break;
case WM_CLOSE:
PostMessage(hDlg, WM_COMMAND, IDC_CANCEL, 0);
break;
}
return FALSE;
}
VOID
vLoadExtCalls(
HWND hExtCalls
)
{
INT iIndex;
UINT uiIndex;
/*
// Load the physical device specific calls
*/
for (uiIndex = 0; uiIndex < HID_DEVCALLS; uiIndex++)
{
iIndex = (INT) SendMessage(hExtCalls,
CB_ADDSTRING,
0,
(LPARAM) DeviceCalls[uiIndex].szFunctionName);
if (CB_ERR != iIndex && CB_ERRSPACE != iIndex)
{
SendMessage(hExtCalls,
CB_SETITEMDATA,
iIndex,
DeviceCalls[uiIndex].uiIndex);
}
}
/*
// Load the other device calls no matter what
*/
for (uiIndex = 0; uiIndex < HID_PPDCALLS; uiIndex++)
{
iIndex = (INT) SendMessage(hExtCalls,
CB_ADDSTRING,
0,
(LPARAM) PpdCalls[uiIndex].szFunctionName);
if (CB_ERR != iIndex && CB_ERRSPACE != iIndex)
{
SendMessage(hExtCalls,
CB_SETITEMDATA,
iIndex,
PpdCalls[uiIndex].uiIndex);
}
}
SendMessage(hExtCalls, CB_SETCURSEL, 0, 0);
return;
}
VOID vSetReportType(
HWND hDlg,
LONG lId
)
{
CheckRadioButton(hDlg, IDC_INPUT, IDC_FEATURE, lId);
return;
}
VOID
vInitEditText(
HWND hText,
INT cbTextSize,
CHAR *pchText
)
{
SendMessage(hText, EM_SETLIMITTEXT, (WPARAM) cbTextSize, 0);
SendMessage(hText, EM_REPLACESEL, 0, (LPARAM) pchText);
return;
}
VOID vEnableParameters(
HWND hDlg,
LRESULT iCallSelection
)
{
EnableWindow(GetDlgItem(hDlg, IDC_INPUT), pState[iCallSelection-1].fInputReport);
EnableWindow(GetDlgItem(hDlg, IDC_OUTPUT), pState[iCallSelection-1].fOutputReport);
EnableWindow(GetDlgItem(hDlg, IDC_FEATURE), pState[iCallSelection-1].fFeatureReport);
EnableWindow(GetDlgItem(hDlg, IDC_REPORTID), pState[iCallSelection-1].fReportID);
EnableWindow(GetDlgItem(hDlg, IDC_USAGEPAGE), pState[iCallSelection-1].fUsagePage);
EnableWindow(GetDlgItem(hDlg, IDC_USAGE), pState[iCallSelection-1].fUsage);
EnableWindow(GetDlgItem(hDlg, IDC_LINKCOLL), pState[iCallSelection-1].fLinkCollection);
EnableWindow(GetDlgItem(hDlg, IDC_INPUT_SELECT), pState[iCallSelection-1].fInputReportSelect);
EnableWindow(GetDlgItem(hDlg, IDC_OUTPUT_SELECT), pState[iCallSelection-1].fOutputReportSelect);
EnableWindow(GetDlgItem(hDlg, IDC_FEATURE_SELECT), pState[iCallSelection-1].fFeatureReportSelect);
return;
}
BOOL
fGetAndVerifyParameters(
HWND hDlg,
PECDISPLAY_PARAMS pParams
)
{
/*
// Declare a text buffer of size 7 since the parameter limit is at most 6
// characters in the edit box.
*/
CHAR WindowText[7];
BOOL fStatus = TRUE;
PCHAR nptr;
if (IsDlgButtonChecked(hDlg, IDC_INPUT))
{
pParams -> ReportType = HidP_Input;
}
else if (IsDlgButtonChecked(hDlg, IDC_OUTPUT))
{
pParams -> ReportType = HidP_Output;
}
else
{
pParams -> ReportType = HidP_Feature;
}
/*
// Get and verify the usage page window text;
*/
GetWindowText(GetDlgItem(hDlg, IDC_USAGEPAGE), WindowText, 7);
pParams -> UsagePage = (USAGE) strtol(WindowText, &nptr, 16);
if (*nptr != '\0')
{
fStatus = FALSE;
pParams -> UsagePage = 0;
}
/*
// Get and verify the usage window text
*/
GetWindowText(GetDlgItem(hDlg, IDC_USAGE), WindowText, 7);
pParams -> Usage = (USAGE) strtol(WindowText, &nptr, 16);
if (*nptr != '\0')
{
fStatus = FALSE;
pParams -> Usage = 0;
}
/*
// Get and verify the link collection window text
*/
GetWindowText(GetDlgItem(hDlg, IDC_LINKCOLL), WindowText, 7);
pParams -> LinkCollection = (USAGE) strtol(WindowText, &nptr, 16);
if (*nptr != '\0')
{
fStatus = FALSE;
pParams -> LinkCollection = 0;
}
GetWindowText(GetDlgItem(hDlg, IDC_REPORTID), WindowText, 7);
pParams -> ReportID = (UCHAR) strtol(WindowText, &nptr, 10);
if (*nptr != '\0')
{
fStatus = FALSE;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?