Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you handle the following mes

Status
Not open for further replies.

sweep123

Technical User
Joined
May 1, 2003
Messages
185
Location
GB
How do you handle the following messages (Not available via Class Wizard)

JOY1BUTTONDOWN()
JOY1BUTTONUP()
and JOY1MOVE()

What I need is a MFC allpication to capture Joystick positions and buttons presses, but cant find how to link in these events to the application.

Regards,
Sweep
 
You can add your own message maps.

Have the class wizard create message maps for something that it can - then look at the code it creates, and modify that to work for the messages that you want.

Hollingside Technologies, Making Technology work for you.
 
If your talking about handling messages like MM_JOY1MOVE etc., You can use the ON_MESSAGE macro in the message map created by the class wizard.

For information about this read the SDK for ON_MESSAGE which contains a link to User Defined Handlers


-pete
 
I have included the following message handling routines but the events are not entered, what have I forgot to do?!?

In the .cpp file:-
BEGIN_MESSAGE_MAP(CMSCPPDlg, CDialog)
//{{AFX_MSG_MAP(CMSCPPDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_GET_STATUS, OnGetStatus)
ON_BN_CLICKED(IDC_START, OnStart)
ON_CBN_EDITCHANGE(IDC_PCNAME, OnEditchangePcname)
//}}AFX_MSG_MAP
ON_MESSAGE(MM_JOY1BUTTONDOWN, OnJoy1ButtonDown)
ON_MESSAGE(MM_JOY1BUTTONUP, OnJoy1ButtonUp)
ON_MESSAGE(MM_JOY1MOVE, OnJoy1Move)
END_MESSAGE_MAP()

In the .h hile:-

class CMSCPPDlg : public CDialog
{
// Construction
public:
LRESULT OnJoy1ButtonUp(WPARAM wParam, LPARAM lParam);
LRESULT OnJoy1ButtonDown(WPARAM wParam, LPARAM lParam);
LRESULT OnJoy1Move(WPARAM wParam, LPARAM lParam);
int m_uiPort;
UDPC m_UDPTx;
CString m_strPCName;
HWND m_hWnd;
CMSCPPDlg(CWnd* pParent = NULL); // standard constructor

The Joy1Move:-
LRESULT CMSCPPDlg::OnJoy1Move(WPARAM wParam, LPARAM lParam)
{
int errorVal; // Error returned from the joyGetPos call

errorVal = joyGetPos(JOYSTICKID1, &joyInfo);
switch (errorVal)
{
case MMSYSERR_NODRIVER :
MessageBox("The joystick driver is not present");
break;
case MMSYSERR_INVALPARAM :
MessageBox("An invalid parameter was passed");
break;
case JOYERR_UNPLUGGED :
MessageBox("The joystick is not connected");
break;
default : // Update the joysticks x,y,z position
formatData.Format("%d", joyInfo.wXpos);
SetDlgItemText(IDC_X, formatData);
formatData.Format("%d", joyInfo.wYpos);
SetDlgItemText(IDC_Y, formatData);
formatData.Format("%d", joyInfo.wZpos);
SetDlgItemText(IDC_Z, formatData);
UpdateData(FALSE);
}
return 0;

}
 
Have you used something like WinSpy to see if the messages are being generated? It may be that another window is handling them.

M.

Hollingside Technologies, Making Technology work for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top