Test whether the mouse is in the window, and test whether the mouse is on the window.

zhaozj2021-02-08  218

Test whether the mouse is in the window, and test whether the mouse is on the window.

FMD (http://www.fmdstudio.net) (Note: This article has appeared in 9cbs and is "original" by others)

Test whether the mouse is in the window, and test whether the mouse is on the window.

The following is given the method of tracking whether the mouse is in the window.

First, use setCapture (), onMousemove (), etc. to determine the mouse position

/ / Set a status amount is used to record and identify if the mouse is in the window

// Bool M_BoverControl;

Void C ????? :: onmousemove (uint nflags, cpoint point)

{

CSTATIC :: OnMousemove (nflags, point);

// If the mouse is still in the window

IF (m_boverControl)

{

CRECT RECT;

GetClientRect (Rect);

// The mouse position left the client area, relieve the mouse capture, and rewrite the status amount m_boverControl

IF (! Rect.ptinRect (Point))

{

m_boverControl = false;

Releasecapture ();

// ......

// Operation when other mice leave

// EG: RedRawwindow ();

Return;

}

}

// If the mouse enters the window, check the mouse capture, status parameters

Else

{

m_boverControl = true;

//

// Operation when other mice enter

// EG: RedRawwindow ();

SetCapture ();

}

}

Second, send WM_MouseEleave messages when using trackmouseevent () to leave the window

Use TrackMouseEvent () to determine the mouse stay and send WM_Mousehover messages

/ / Set a status amount is used to record and identify if the mouse is in the window

// bool m_bmousetracking;

// Test a mouse mobile message

Void Csomew :: OnMousemove (uint nflags, cpoint point)

{

// Receive WM_MOUSEMOVE, and m_bmousetracking is a false, the mouse enters the window.

// Set _trackmouseevent

IF (! m_bmousetracking)

{

TrackMouseEvent TME;

Tme.cbsize = sizeof (trackmouseevent);

/ / Monitor the mouse to leave

Tme.dwflags = TME_LEVE;

Tme.hwndtrack = this-> m_hwnd;

IF (:: _ TRACKMOUSEEVENT (& TME))

{

m_bmousetracking = true;

//

// Operation when other mice enter

//

}

}

CView :: OnMousemove (NFLAGS, POINT);

}

//

/ / Treat WM_MOUSELEAVE message

//

// message processing function declaration

AFX_MSG LRESULT ONMOUSELEAVE (WPARAM WPARAM, LPARAM LPARAM);

// message mapping

ON_MESSAGE (WM_MOUSELEAVE, ONMOUSELEAVE)

// Processing function definition

LResult Csomewnd :: OnMouseLeave (WParam WPARAM, LPARAM LPARAM)

{

//

// Operation when other mice leave

//

// Reset status quantity

m_bmousetracking = false;

Return True;

}

转载请注明原文地址:https://www.9cbs.com/read-3133.html

New Post(0)