-
June 1st, 2009, 11:29 PM
#1
Checking for mouse press
Hello everyone, glad to finally be on here after many months looking though all the help you have all given. I am having a problem with my code, I am trying to get it to handle a mouse press, and then get it to display another image. I have tried everything and am still unable to get my image to flip to my next image.
// Checks to see if the mouse is within a certain range of x, y
if((p.x > 8) && (p.x < 118))
{
// Checks to see if the mouse is within a certain range of x, y
if ((p.y > 66) && (p.y < 114))
{
// If mouse is within range, highlight the selected option
mml = MM_RESUME;
//Check to see if the left mouse has been pressed
if(GetKeyState(VK_LBUTTON & 0x80))
{
// Display Demo image if button has been pressed
VisualManager::Get()->Demo();
}
}
}
Am I using VK_LBUTTON wrong?
-
June 2nd, 2009, 12:58 AM
#2
Re: Checking for mouse press
May be you can handle your operations in WM_LBUTTONDOWN and WM_MOUSEMOVE... it might be easier to handle the functionality....
Thanks...
-
June 2nd, 2009, 10:02 AM
#3
Re: Checking for mouse press
I tried that, and it still won't open up my other image. The mouse over works, it flips the image to highlight the option I am over, but when I click on it, nothing happens. Do I need to use mouse_event()? If so how would I use it.
-
June 2nd, 2009, 07:25 PM
#4
Re: Checking for mouse press
What happens when you just execute:
Code:
VisualManager::Get()->Demo();
Create a menu item for it and a function for the menu item. Are you sure that VisualManager::Get()->Demo(); does something?
-
June 3rd, 2009, 12:32 PM
#5
Re: Checking for mouse press
Yes,
VisualManager::Get()->Demo();
is my call to draw my new image. I have tested out, and it works fine when I don't use any mouse input. I am just having trouble making my code have mouse input.
-
June 3rd, 2009, 05:08 PM
#6
Re: Checking for mouse press
All you have to do is use CWND::OnLButtonDown it determines if the left button is down so you don't have to get involved with VK_LBUTTON(?).
Code:
OnLButtonDown(UINT nFlags, CPoint point)
{
CPoint x;
x = point;
if((p.x > 8) && (p.x < 118))
{
// Checks to see if the mouse is within a certain range of x, y
if ((p.y > 66) && (p.y < 114))
{
// Display Demo image if button has been pressed
VisualManager::Get()->Demo();
}
}
....
}
Like said above, LeftButton is already flaged for you.
-
June 3rd, 2009, 10:41 PM
#7
Re: Checking for mouse press
Originally Posted by Dex83
I tried that, and it still won't open up my other image. The mouse over works, it flips the image to highlight the option I am over, but when I click on it, nothing happens. Do I need to use mouse_event()? If so how would I use it.
As i said earlier.... Use the message events for the left mouse button click... you can find this in Class wizard of your project.... look for WM_LBUTTONDOWN and handle the functionality over there.... !!!
Hope this helps,
Thanks.
-
June 4th, 2009, 12:53 AM
#8
Re: Checking for mouse press
I use these macros:
Code:
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? true : false)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? false : true)
so:
Code:
// Checks to see if the mouse is within a certain range of x, y
if((p.x > 8) && (p.x < 118))
{
// Checks to see if the mouse is within a certain range of x, y
if ((p.y > 66) && (p.y < 114))
{
// If mouse is within range, highlight the selected option
mml = MM_RESUME;
//Check to see if the left mouse has been pressed
if(KEY_DOWN(VK_LBUTTON))
{
// Display Demo image if button has been pressed
VisualManager::Get()->Demo();
}
}
}
This works fine for me. You might want to but a breakpoint at VisualManager::Get()->Demo(); to make sure that the problem is with the mouse detection and not your image-switching code.
-
June 5th, 2009, 01:33 AM
#9
Re: Checking for mouse press
Awesome thanks guys, that really helped a lot. I like defining the KEY_DOWN, and KEY_UP. Never thought to do it that way.
-
June 5th, 2009, 03:57 PM
#10
Re: Checking for mouse press
Originally Posted by Dex83
Awesome thanks guys, that really helped a lot. I like defining the KEY_DOWN, and KEY_UP. Never thought to do it that way.
Well there is a way to show your appreciation. ... that's what most of these guys and myself response to posters who are in bad situations or are stuck.
... it also keeps these posters helping you in the future if you get stuck or need help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|