////////////////////////////////////////////////////////////
// Hello2.cpp
#include <windows.h>
#include "KWnd.h"
#include <stdio.h>
#include <wtypes.h>
extern "C" {
#include "hidsdi.h"
#include "setupapi.h"
}
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int i = 0;
////////////////////////////////////////////////////////////////////////////////////////////////////
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
MSG msg;
KWnd mainWnd("A Hello2 application", hInstance, nCmdShow, WndProc);
while (GetMessage(&msg, NULL, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
HRGN hRgn;
////////////////////////////////////////////////////////////////////////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
HDC hDC;
PAINTSTRUCT ps;
RECT rect;
char buffer [30];
char buffer1 [30];
int userReply;
HANDLE DeviceHandle;
GUID
HidGuid;
ULONG
Length;
HANDLE hDevInfo;
ULONG
Required;
HIDP_CAPS Capabilities;
HANDLE ReadHandle;
HANDLE hEventObject;
OVERLAPPED HIDOverlapped;
BYTE
InputReport[21];
BYTE
OutputReport[21];
DWORD
NumberOfBytesRead;
PSP_DEVICE_INTERFACE_DETAIL_DATA detailData;
bool
DeviceDetected;
//CHANNELS Channels;
DWORD WINAPI ReadThread();
HIDD_ATTRIBUTES Attributes;
SP_DEVICE_INTERFACE_DATA devInfoData;
bool
LastDevice = FALSE;
int
MemberIndex = 0;
bool
MyDeviceDetected = FALSE;
LONG
Result;
//These are the vendor and product IDs to look for.
const unsigned int VendorID = 0x3208;
const unsigned int ProductID = 0x4840;
Length = 0;
detailData = NULL;
DeviceHandle=NULL;
ULONG inputBuffer;
/*
API function: HidD_GetHidGuid
Get the GUID for all system HIDs.
Returns: the GUID in HidGuid.
*/
switch (uMsg)
{
case WM_CREATE:
HidD_GetHidGuid(&HidGuid);
hDevInfo=SetupDiGetClassDevs
(&HidGuid, NULL, NULL, DIGCF_PRESENT|DIGCF_INTERFACEDEVICE);
devInfoData.cbSize = sizeof(devInfoData);
MemberIndex = 0;
LastDevice = FALSE;
//do
//{
for(0;i<2;i++){
MyDeviceDetected=FALSE;
Result=SetupDiEnumDeviceInterfaces (hDevInfo,
0, &HidGuid, MemberIndex, &devInfoData);
if (Result != 0)
{
Result = SetupDiGetDeviceInterfaceDetail
(hDevInfo, &devInfoData, NULL, 0, &Length, NULL);
detailData = (PSP_DEVICE_INTERFACE_DETAIL_DATA)malloc(Length);
detailData -> cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
Result = SetupDiGetDeviceInterfaceDetail
(hDevInfo, &devInfoData, detailData, Length, &Required, NULL);
DeviceHandle=CreateFile
(detailData->DevicePath,
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
0,
NULL);
Attributes.Size = sizeof(Attributes);
Result = HidD_GetAttributes
(DeviceHandle,
&Attributes);
MyDeviceDetected = FALSE;
HidD_GetNumInputBuffers(DeviceHandle,&inputBuffer);
MemberIndex++;
}
}
//} //do
//while ((LastDevice != FALSE) && (MyDeviceDetected == FALSE));
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
GetClientRect(hWnd, &rect);
// DrawText(hDC, "Hello, World!", -1, &rect,
// DT_SINGLELINE | DT_CENTER | DT_VCENTER );
sprintf(buffer,"HidName= %d",detailData->DevicePath);
TextOut(hDC, 10,10, buffer,10 );
sprintf(buffer1,"VendorID= %d, ProductID=%d, VersionNumber=%d\0",Attributes.VendorID,Attributes.ProductID,Attributes.VersionNumber);
TextOut(hDC, 10,30, buffer1,59 );
sprintf(buffer,"×èñëî âõîäíûõ áóôåðîâ= %d",&inputBuffer);
TextOut(hDC, 10,50, buffer,40 );
EndPaint(hWnd, &ps);
break;
case WM_CLOSE:
SetupDiDestroyDeviceInfoList(hDevInfo);
userReply = MessageBox(hWnd, "À âû óâåðåíû â ñâîåì æåëàíèè çàêðûòü ïðèëîæåíèå?",
"", MB_YESNO | MB_ICONQUESTION);
if (IDYES == userReply)
DestroyWindow(hWnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
return 0;
}