[RESOLVED] why Mouse Enter\Leave\Hover don't work normaly?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: [RESOLVED] why Mouse Enter\Leave\Hover don't work normaly?

  1. #1
    Join Date
    Apr 2009
    Posts
    596

    [RESOLVED] why Mouse Enter\Leave\Hover don't work normaly?

    i'm learning more about windows messages:
    Code:
    void TrackMouse(HWND hwnd)
    {
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_HOVER | TME_LEAVE; //Type of events to track & trigger.
        tme.dwHoverTime = 1; //How long the mouse has to be in the window to trigger a hover event.
        tme.hwndTrack = hwnd;
        TrackMouseEvent(&tme);
    }
    // Step 4: the Window Procedure
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
        static bool Tracking = false;
    
        switch(msg)
        {
            case WM_CLOSE:
                DestroyWindow(hwnd);
            break;
            case WM_KEYUP:
                if (wParam ==VK_ESCAPE)
                    DestroyWindow(hwnd);
                else
                {
                    char strDataToSend[32];
                    sprintf(strDataToSend, "%c", wParam);
                    MessageBox(NULL,strDataToSend, "keyselected",MB_OK);
                }
            break;
    
            case WM_MOUSEMOVE:
                if (!Tracking)
                {
                    TrackMouse(hwnd);
                    Tracking = true;
                    SetWindowText(hwnd,"MOUSE Entered");
                }
                break;
            case WM_MOUSEHOVER:
                SetWindowText(hwnd,"MOUSE hover");
                break;
            case WM_MOUSELEAVE:
                SetWindowText(hwnd,"MOUSE LEFT");
                Tracking = false;
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            default:
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }
    i see some problems:
    - the mouse leave and mouse hover works in same time... why?
    - the mouse messages work with client size and not window size, why?(i'm confused here)

  2. #2
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,883

    Re: why Mouse Enter\Leave\Hover don't work normaly?

    Quote Originally Posted by Cambalinho View Post
    i see some problems:
    - the mouse leave and mouse hover works in same time... why?
    I just made a sample and never saw the effect.

    - the mouse messages work with client size and not window size, why?(i'm confused here)
    It's just because you specify tracking flags for client area only.

    See the sample: HOWTO-hover-leave-client-nonclient.zip
    Best regards,
    Igor

  3. #3
    Join Date
    Apr 2009
    Posts
    596

    Re: why Mouse Enter\Leave\Hover don't work normaly?

    Quote Originally Posted by Igor Vartanov View Post
    I just made a sample and never saw the effect.

    It's just because you specify tracking flags for client area only.

    See the sample: HOWTO-hover-leave-client-nonclient.zip
    i found my error with mouse hover: tme.dwHoverTime = 1;
    i changed the timer and works
    how i can calculate the mouse wheel position?(for see if goes down\up or left\right)
    how can i test if the ctrl\alt\shift keys was pressed?

  4. #4
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,015

    Re: why Mouse Enter\Leave\Hover don't work normaly?

    how i can calculate the mouse wheel position?(for see if goes down\up or left\right)
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    how can i test if the ctrl\alt\shift keys was pressed?
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Also
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    You should take some time to look at msdn.microsoft.com. This site has a lot of veryuseful information regarding development.
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  5. #5
    Join Date
    Apr 2009
    Posts
    596

    Re: why Mouse Enter\Leave\Hover don't work normaly?

    Quote Originally Posted by 2kaud View Post
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx


    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    Also
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    You should take some time to look at msdn.microsoft.com. This site has a lot of veryuseful information regarding development.
    and read more.. thanks for all

  6. #6
    Join Date
    Dec 2012
    Location
    England
    Posts
    2,015

    Re: [RESOLVED] why Mouse Enter\Leave\Hover don't work normaly?

    Note for consoles, use
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    which has a mouse event record
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    which contains info abot button presses, wheel movement, button states etc
    All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.

  7. #7
    Join Date
    Apr 2009
    Posts
    596

    Re: [RESOLVED] why Mouse Enter\Leave\Hover don't work normaly?

    Quote Originally Posted by 2kaud View Post
    Note for consoles, use
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    which has a mouse event record
    http://msdn.microsoft.com/en-us/libr...=vs.85%29.aspx

    which contains info abot button presses, wheel movement, button states etc
    speaking on console: the mouse move event have a bug?
    why the question? because when i move the mouse and then stop, after some milliseconds(on loop time) the mouse move is activated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center