Sign in to follow this  

Need help with mouse

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have downloaded and read through the NeHe OpenGL tutorials but I am having trouble with the mouse. I have discovered how to read its position but I dont know how to detect if a button is being clicked. if im not mistaken Wndproc takes care of all the messages sent by windows and I think windows would post a mesage when the mouse is clicked I just dont know what the message is and I need some help to syntax it. Thanx ppl

Share this post


Link to post
Share on other sites
The message is WM_LBUTTONDOWN. It is sent when the user presses the left button down. There are also messages like WM_MBUTTONDOWN and WM_RBUTTONUP etc. See the MSDN (the Notifications section).

To handle the message just add something like the following case statement to your WndProc and return 0 when you're done handling the message.




LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int x, y;

switch (message)
{

....

case WM_LBUTTONDOWN:
/* the coordinates where the click happened */
x=LOWORD(lParam);
y=HIWORD(lParam);

/* wParam contains some info about certain keys
and the mouse buttons. Again, see the msdn. */


break;
....
}

return 0;




edit: corrected the example

Share this post


Link to post
Share on other sites

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this