CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    Jun 2009
    Posts
    4

    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?

  2. #2
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    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...

  3. #3
    Join Date
    Jun 2009
    Posts
    4

    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.

  4. #4
    Join Date
    Apr 2009
    Posts
    57

    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?

  5. #5
    Join Date
    Jun 2009
    Posts
    4

    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.

  6. #6
    Join Date
    Apr 2009
    Posts
    57

    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.

  7. #7
    Join Date
    Aug 2008
    Location
    India
    Posts
    186

    Re: Checking for mouse press

    Quote Originally Posted by Dex83 View Post
    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.

  8. #8
    Join Date
    May 2009
    Posts
    33

    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.

  9. #9
    Join Date
    Jun 2009
    Posts
    4

    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.

  10. #10
    Join Date
    Apr 2009
    Posts
    57

    Re: Checking for mouse press

    Quote Originally Posted by Dex83 View Post
    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
  •  





Click Here to Expand Forum to Full Width

Featured