Thread View: borland.public.cppbuilder.multimedia
5 messages
5 total messages
Started by Edward
Thu, 09 Dec 2004 17:25
Joystick Button Problems
Author: Edward
Date: Thu, 09 Dec 2004 17:25
Date: Thu, 09 Dec 2004 17:25
122 lines
4129 bytes
4129 bytes
Why i can get the butons 5,6,7 and 8 of my USB Joystick?
Best Regards,
Edward.
My code
void __fastcall TFormPrincipal::FormCreate(TObject *Sender)
{
MMRESULT jr;
JOYINFOEX JoyInfo;
int joycount=joyGetNumDevs();
if (joycount=0)
Memo1->Lines->Add("ok 1");
else
{
connect=false;
jr=joyGetPosEx(JOYSTICKID1,&JoyInfo);
if (jr ==JOYERR_NOERROR)
{
connect=true;
jnum= JOYSTICKID1;
}
else
if (jr == MMSYSERR_INVALPARAM)
ShowMessage("deu merda");
else if((jr=joyGetPosEx(JOYSTICKID2,&JoyInfo)) == JOYERR_NOERROR)
{
connect = true;
jnum= JOYSTICKID2;
}
}
joyGetDevCaps(jnum,&JoyCaps, sizeof(JOYCAPS));
if (connect)
Memo1->Lines->Add("Conected") ;
Memo1->Lines->Add("jnum : "+ IntToStr(jnum));
Memo1->Lines->Add("JoyCaps.szPnam : " + AnsiString(JoyCaps.szPname));
Memo1->Lines->Add("JoyCaps.wNumButtons : " +
IntToStr(JoyCaps.wNumButtons));
if (connect)
{
joySetCapture(Handle,jnum,2*JoyCaps.wPeriodMin,FALSE);
}
stepX = (JoyCaps.wXmax - JoyCaps.wXmin) / PaintBox1->Width;
stepY = (JoyCaps.wYmax - JoyCaps.wYmin) / PaintBox1->Height;
}
//---------------------------------------------------------------------------
void __fastcall TFormPrincipal::FormDestroy(TObject *Sender)
{
if (connect)
joyReleaseCapture(jnum);
}
//---------------------------------------------------------------------------
void __fastcall TFormPrincipal::UpdButton(TMessage &msg)
{
Shape1->Visible= (msg.WParam &JOY_BUTTON1);
Shape2->Visible= (msg.WParam &JOY_BUTTON2);
Shape3->Visible= (msg.WParam &JOY_BUTTON3);
Shape4->Visible= (msg.WParam &JOY_BUTTON4);
Shape5->Visible= (msg.WParam &JOY_BUTTON5);
Shape6->Visible= (msg.WParam &JOY_BUTTON6);
Shape7->Visible= (msg.WParam &JOY_BUTTON7);
Shape8->Visible= (msg.WParam &JOY_BUTTON8);
}
//---------------------------------------------------------------------------
void __fastcall TFormPrincipal::UpdCoord(TMessage &msg)
{
JOYINFO JoyInfo;
TCanvas *pCanvas = PaintBox1->Canvas;
pCanvas->Brush->Color=FormPrincipal->Color;
pCanvas->FillRect(Rect(0,0,PaintBox1->Width,PaintBox1->Height));
Pos.x = msg.LParamLo;
Pos.y = msg.LParamHi;
int x=(Pos.x-JoyCaps.wXmin)/stepX-ImageList1->Width/2;
int y=(Pos.y-JoyCaps.wYmin)/stepY-ImageList1->Height/2;
ImageList1->Draw(pCanvas,x,y,0,true);
}
//---------------------------------------------------------------------------
void __fastcall FormDestroy(TObject *Sender);
void __fastcall UpdButton(TMessage &msg);
void __fastcall UpdCoord(TMessage &msg);
.h
private:
int jnum;
bool connect;
int stepX,stepY;
TPoint Pos;
public:
__fastcall TFormPrincipal(TComponent* Owner);
BEGIN_MESSAGE_MAP
MESSAGE_HANDLER(MM_JOY1BUTTONDOWN,TMessage,UpdButton);
MESSAGE_HANDLER(MM_JOY1BUTTONUP,TMessage,UpdButton);
MESSAGE_HANDLER(MM_JOY1MOVE,TMessage,UpdCoord);
MESSAGE_HANDLER(MM_JOY2BUTTONDOWN,TMessage,UpdButton);
MESSAGE_HANDLER(MM_JOY2BUTTONUP,TMessage,UpdButton);
MESSAGE_HANDLER(MM_JOY2MOVE,TMessage,UpdCoord);
END_MESSAGE_MAP(TForm);
};
Re: Joystick Button Problems
Author: Remy Lebeau (TeamB)
Date: Thu, 09 Dec 2004 17:31
Date: Thu, 09 Dec 2004 17:31
20 lines
1568 bytes
1568 bytes
"Edward" <eduglobo2004@globo.com> wrote in message news:41b88a74@newsgroups.borland.com... > Why i can get the butons 5,6,7 and 8 of my USB Joystick? What exactly are you having a problem with? Please be more specific. > void __fastcall TFormPrincipal::FormCreate(TObject *Sender) Do not use the OnCreate event. It is a Delphi remnant that can be triggered before the constructor, which is illegal in C++. Use the actual constructor instead. > void __fastcall TFormPrincipal::FormDestroy(TObject *Sender) Do not use the OnDestroy event. It can be triggered after the destructor, which is also illegal in C++. Use the actual destructor instead. Gambit
Re: Joystick Button Problems
Author: Edward
Date: Thu, 09 Dec 2004 18:14
Date: Thu, 09 Dec 2004 18:14
65 lines
2565 bytes
2565 bytes
If is illegal, why exist? Please be more clearly.
I can use FormActivate in the place of FormCreate?
void __fastcall TFormPrincipal::FormActivate(TObject *Sender)
{
}
And
void __fastcall TFormPrincipal::FormClose(TObject *Sender, TCloseAction
&Action)
{
}
in the place of FormDestroy ?
MY QUESTION :
Why i CAN NOT get the butons 5,6,7 and 8 of my USB Joystick?
When i press the buttons 1, 2, 3, and 4 all works fine...
Shape1->Visible= (msg.WParam &JOY_BUTTON1);
Shape2->Visible= (msg.WParam &JOY_BUTTON2);
Shape3->Visible= (msg.WParam &JOY_BUTTON3);
Shape4->Visible= (msg.WParam &JOY_BUTTON4);
Understand ?
And when i press
5,6,7,8 my code not work...
Thank you
Edward
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:41b88bd4$2@newsgroups.borland.com...
>
> "Edward" <eduglobo2004@globo.com> wrote in message
> news:41b88a74@newsgroups.borland.com...
>> Why i can get the butons 5,6,7 and 8 of my USB Joystick?
>
> What exactly are you having a problem with? Please be more specific.
>
>> void __fastcall TFormPrincipal::FormCreate(TObject *Sender)
>
> Do not use the OnCreate event. It is a Delphi remnant that can be
> triggered
> before the constructor, which is illegal in C++. Use the actual
> constructor
> instead.
>
>> void __fastcall TFormPrincipal::FormDestroy(TObject *Sender)
>
> Do not use the OnDestroy event. It can be triggered after the destructor,
> which is also illegal in C++. Use the actual destructor instead.
>
>
> Gambit
>
>
Re: Joystick Button Problems
Author: Remy Lebeau (TeamB)
Date: Thu, 09 Dec 2004 19:17
Date: Thu, 09 Dec 2004 19:17
42 lines
2580 bytes
2580 bytes
"Edward" <eduglobo2004@globo.com> wrote in message news:41b89609@newsgroups.borland.com... > If is illegal, why exist? They exist because the same VCL is shared between both Delphi and BCB, but the VCL is written in Delphi Pascal, not C++. They are legal in Delphi, because Delphi Pascal has different rules regarding how objects are created than C++ does. Being written in Pascal, the VCL in BCB follows the Delphi rules, not the C++ rules. That is why those events are dangerous to use in C++ but not in Delphi. > I can use FormActivate in the place of FormCreate? The OnActivate event is not a constructor. Not only that, it can be triggered multiple times, so you have to watch out for that. > void __fastcall TFormPrincipal::FormClose(TObject *Sender, TCloseAction > &Action) <snip> > in the place of FormDestroy ? The OnClose event is not always guaranteed to be triggered. There are situations where it is skipped, so your clean up code would not be called at all. That is why I told you to use the actual destructor instead. It seems to me that you are focusing too much on the Object Inspector and not enough on the actual code. > Why i CAN NOT get the butons 5,6,7 and 8 of my USB Joystick? The message you are catching does not support those buttons in the first place. It only supports the first four buttons. Rather than using the Joystick API, I would suggest you use DirectX instead, specially DirectInput. Microsoft even says that the Joystick API has been superseded by DirectInput because it has more features for supporting modern technology. Gambit
Re: Joystick Button Problems
Author: Edward
Date: Thu, 09 Dec 2004 19:30
Date: Thu, 09 Dec 2004 19:30
62 lines
3087 bytes
3087 bytes
Ok Thank You Gambit. I will search some samples in Direct X. To much thinks to do and to few time to study. Edward "Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:41b8a4c7$1@newsgroups.borland.com... > > "Edward" <eduglobo2004@globo.com> wrote in message > news:41b89609@newsgroups.borland.com... > >> If is illegal, why exist? > > They exist because the same VCL is shared between both Delphi and BCB, but > the VCL is written in Delphi Pascal, not C++. They are legal in Delphi, > because Delphi Pascal has different rules regarding how objects are > created > than C++ does. Being written in Pascal, the VCL in BCB follows the Delphi > rules, not the C++ rules. That is why those events are dangerous to use > in > C++ but not in Delphi. > >> I can use FormActivate in the place of FormCreate? > > The OnActivate event is not a constructor. Not only that, it can be > triggered multiple times, so you have to watch out for that. > >> void __fastcall TFormPrincipal::FormClose(TObject *Sender, TCloseAction >> &Action) > <snip> >> in the place of FormDestroy ? > > The OnClose event is not always guaranteed to be triggered. There are > situations where it is skipped, so your clean up code would not be called > at > all. That is why I told you to use the actual destructor instead. > > It seems to me that you are focusing too much on the Object Inspector and > not enough on the actual code. > >> Why i CAN NOT get the butons 5,6,7 and 8 of my USB Joystick? > > The message you are catching does not support those buttons in the first > place. It only supports the first four buttons. > > Rather than using the Joystick API, I would suggest you use DirectX > instead, > specially DirectInput. Microsoft even says that the Joystick API has been > superseded by DirectInput because it has more features for supporting > modern > technology. > > > Gambit > >
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads