MFC Mouse Event Handling Questions.

Asked 1 years ago, Updated 1 years ago, 463 views

WM_LBUTTONDOWN, WM_MOUSEMOVE, WM_RBUTTONDOWN 등 If all mouse events are handled in the same location, the coordinate values of the mouse where the event occurred are the same

Only WM_MOUSEWHEEL has different coordinates of the mouse where the event occurred. I wonder why.

Click Event

void CPr2View::OnLButtonDown(UINT nFlags, CPoint point)
{
    m_strPointText.Format(_T("%d %d "), point.x, point.y);
    OutputDebugString(m_strPointText);
    Invalidate();

    CView::OnLButtonDown(nFlags, point);
}

Wheel events

BOOL CPr2View::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
{
    if (zDelta < 0)
    {
        m_strPointText.Format(_T("%d %d "), pt.x, pt.y);
        OutputDebugString(m_strPointText);
    }
    else
    {
        m_strPointText.Format(_T("%d %d "), pt.x, pt.y);
        OutputDebugString(m_strPointText);
    }

    return CView::OnMouseWheel(nFlags, zDelta, pt);
}

The result is left click in the same position in the executed window, moving the wheel. (49, 617) (267, 902) has different coordinate values.

Same coordinates as when left-clicked (49, 617), except for wheel events such as right-click and mouse movement.

And how do you get these coordinate values to be the same?

mfc c++ win32

2023-01-27 02:50

1 Answers

The point of OnLButtonDown(UINTnFlags, CPpoint) is the coordinate in the client area, and in BOOL CPr2View::OnMouseWheel(UINTnFlags, short zDelta, CPpoint pt), pt is the absolute coordinate of the screen monitor.

BOOL CPr2View::OnMouseWheel(UINTnFlags, short zDelta, CPointt) Add one line below to the first line of the function, and you can change the screen coordinates to client coordinates and see the same coordinate value.

ScreenToClient(&pt);


2023-01-27 16:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.