CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Apr 2009
    Posts
    1,355

    [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
    6,620

    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
    1,355

    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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,821

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  5. #5
    Join Date
    Apr 2009
    Posts
    1,355

    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
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,821

    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. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  7. #7
    Join Date
    Apr 2009
    Posts
    1,355

    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
  •  





Click Here to Expand Forum to Full Width

Featured