locked
how detect mouse stoped, window stoped and window resized windows messages? RRS feed

  • Question

  • void TrackMouse(HWND hwnd)
    {
        TRACKMOUSEEVENT tme;
        tme.cbSize = sizeof(TRACKMOUSEEVENT);
        tme.dwFlags = TME_HOVER | TME_LEAVE; //Type of events to track & trigger.
        tme.dwHoverTime = 5000; //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;
        static bool StopMoving = NULL;
    
        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_MOVING:
                SetWindowText(hwnd,"window move");
                StopMoving=false;
                break;
            case WM_SIZE :
                SetWindowText(hwnd,"Resized");
                break;
            case WM_DESTROY:
                PostQuitMessage(0);
                break;
            case WM_NCLBUTTONUP:
                SetWindowText(hwnd,"stop Resized");
                break;
            default:
    
                return DefWindowProc(hwnd, msg, wParam, lParam);
        }
        return 0;
    }

    if i use WM_NCLBUTTONUP message, seems be ignored.

    if i use WM_EXITSIZEMOVEMODE message, seems freeze the window :(

    so how can i detect the exit size and exit move messages?

    and how can i detect the mouse stoped?(not mouse hover)

    Tuesday, November 12, 2013 9:16 PM

Answers

  • You are not calling DefWindowProc for any messages you are handling. You should always call DefWindowProc, unless there's a specific reason to suppress default behavior. Move DefWindowProc call out of the switch statement, to where you currently have "return 0;"

    Igor Tandetnik

    sorry about that.. i learn from here: http://www.winprog.org/tutorial/window_click.html

    but the correct message is: WM_EXITSIZEMOVE .

    and with 2 stactic bool i track the size and move.. very cool ;)

    (i will share de code ;))

    but tell me, if you know, instead a timer, is there another way for track the mouse stoped?

    Tuesday, November 12, 2013 11:55 PM

All replies

  • You are not calling DefWindowProc for any messages you are handling. You should always call DefWindowProc, unless there's a specific reason to suppress default behavior. Move DefWindowProc call out of the switch statement, to where you currently have "return 0;"

    Igor Tandetnik

    Tuesday, November 12, 2013 11:28 PM
  • You are not calling DefWindowProc for any messages you are handling. You should always call DefWindowProc, unless there's a specific reason to suppress default behavior. Move DefWindowProc call out of the switch statement, to where you currently have "return 0;"

    Igor Tandetnik

    sorry about that.. i learn from here: http://www.winprog.org/tutorial/window_click.html

    but the correct message is: WM_EXITSIZEMOVE .

    and with 2 stactic bool i track the size and move.. very cool ;)

    (i will share de code ;))

    but tell me, if you know, instead a timer, is there another way for track the mouse stoped?

    Tuesday, November 12, 2013 11:55 PM
  • but tell me, if you know, instead a timer, is there another way for track the mouse stoped?

    What does "stopped" mean, if not "the mouse hasn't moved for a certain period of time"? Computer mice don't typically come with an accelerometer inside.

    Igor Tandetnik

    Wednesday, November 13, 2013 12:37 AM