Board index » cppbuilder » RegisterRawInputDevices WM_INPUT ????

RegisterRawInputDevices WM_INPUT ????


2007-02-10 06:42:05 AM
cppbuilder97
hi all ,
I try to find a simple application that register a hid to get his raw data.
I have try this code, but i not receive the wm_input message:
HEADER
class TForm5 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm5(TComponent* Owner);
void WindowProc(TMessage &msg);
BEGIN_MESSAGE_MAP
VCL_MESSAGE_HANDLER(WM_INPUT,TMessage,WindowProc);
END_MESSAGE_MAP(TForm)
};
CPP file
void __fastcall TForm5::Button1Click(TObject *Sender)
{
RAWINPUTDEVICE Rid;
Rid.usUsagePage = 0x01;
Rid.usUsage = 0x04;
Rid.dwFlags = 0; // adds joystick
Rid.hwndTarget = NULL;
if (RegisterRawInputDevices(&Rid, 1, sizeof(Rid)) == FALSE)
{
//registration failed. Call GetLastError for the cause of the error.
ShowMessage("error");
}
}
//---------------------------------------------------------------------------
void TForm5::WindowProc(TMessage &msg)
{
ShowMessage("WM_INPUT");
}
this is for a joystick device.
regards
Jonathan
 
 

Re:RegisterRawInputDevices WM_INPUT ????

"Jonathan Dumaresq" < XXXX@XXXXX.COM >wrote in message
Quote
void WindowProc(TMessage &msg);
TForm inherits a WindowProc property from TControl. You cannot
declare a method with the same name. You should override the virtual
WndProc() method instead.
Quote
RAWINPUTDEVICE Rid;
You should always zero out API structures before using them:
RAWINPUTDEVICE Rid = {0};
Or
RAWINPUTDEVICE Rid;
memset(&Rid, 0, sizeof(Rid));
Or:
RAWINPUTDEVICE Rid;
::ZeroMemory(&Rid, sizeof(Rid));
Quote
Rid.usUsagePage = 0x01;
Rid.usUsage = 0x04;
Rid.dwFlags = 0; // adds joystick
Rid.hwndTarget = NULL;
Why are you not setting the TForm's Handle as the target? That is
where you are trying to catch the WM_INPUT messages, afterall.
Quote
if (RegisterRawInputDevices(&Rid, 1, sizeof(Rid)) == FALSE)
{
//registration failed. Call GetLastError for the cause of the
error.
ShowMessage("error");
}
You did not say which error is actually being reported.
Gambit
 

Re:RegisterRawInputDevices WM_INPUT ????

Quote

>void WindowProc(TMessage &msg);

TForm inherits a WindowProc property from TControl. You cannot
declare a method with the same name. You should override the virtual
WndProc() method instead.
good. I have found it after posting it.
Quote

>RAWINPUTDEVICE Rid;

You should always zero out API structures before using them:
I have do it also.
Quote
>Rid.hwndTarget = NULL;
i think this was my error. The first time i try it i put 'this' instead of
Handle.
Quote
>if (RegisterRawInputDevices(&Rid, 1, sizeof(Rid)) == FALSE)
>{
>//registration failed. Call GetLastError for the cause of the
error.
>ShowMessage("error");
>}

You did not say which error is actually being reported.
I have not put it because i have no error.
BUT THANKS AGAIN GAMBIT. this is now working. I got my event :)
do i have to put something at the end of the wndproc to redispatch the
messages ?
regards
Jonathan
 

{smallsort}

Re:RegisterRawInputDevices WM_INPUT ????

Hi again,
Is it possible to use
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_INPUT TMessage, WMInput)
END_MESSAGE_MAP(TComponent)
to get only the WM__INPUT ?
if yes, what i should put for parameter to END_MESSAGE_MAP ?
Jonathan
 

Re:RegisterRawInputDevices WM_INPUT ????

Quote
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(WM_INPUT TMessage, WMInput)
END_MESSAGE_MAP(TComponent)

to get only the WM__INPUT ?

if yes, what i should put for parameter to END_MESSAGE_MAP ?

Jonathan
forget it. I try it and it's work. I put TForm as the parametrer.
Jonathan