– SetCapture() 함수처럼 마우스 이벤트를 추적할 수 있도록 해줍니다. 그러나 동작 원리를 놓고 보면 두 함수는 너무나 다른 함수입니다. 마우스가 자신의 윈도우 영역을 벗어났음을 감지하는 방법에서, SetCapture() 함수는 응용 프로그램 자신이 직접 마우스를 점유하고 계속 마우스 메시지를 수신하여 경계를 벗어났는지 검사하지만, _TrackMouseEvent() 함수는 운영체제에 자신의 윈도우를 등록하여 마우스가 자신의 영역을 벗어나면 메시지(WM_MOUSELEAVE)를 수신하여 경계가 벗어났음을 판단합니다.

– VS2008에서 WM_MOUSELEAVE 메시지에 대한 핸들러를 자동으로 추가하실 수 있습니다.
Return code Description
Message

Meaning

WM_NCMOUSEHOVER

Windows 98/Me, Windows 2000/XP: The same meaning as WM_MOUSEHOVER except this is for the nonclient area of the window.

WM_NCMOUSELEAVE

Windows 98/Me, Windows 2000/XP: The same meaning as WM_MOUSELEAVE except this is for the nonclient area of the window.

WM_MOUSEHOVER

The mouse hovered over the client area of the window for the period of time specified in a prior call to TrackMouseEvent. Hover tracking stops when this message is generated. The application must call TrackMouseEvent again if it requires further tracking of mouse hover behavior.

WM_MOUSELEAVE

The mouse left the client area of the window specified in a prior call to TrackMouseEvent. All tracking requested byTrackMouseEvent is canceled when this message is generated. The application must call TrackMouseEvent when the mouse reenters its window if it requires further tracking of mouse hover behavior.

Requirements

Minimum supported client

Windows XP

Minimum supported server

Windows 2000 Server

Header

Winuser.h (include Windows.h)

Library

User32.lib

DLL

User32.dll

Unicode and ANSI names

TrackMouseEventW (Unicode)
===================
샘플코드)
void CSkinButton::CheckHover()
{
if (!IsWindowEnabled())
return;

TRACKMOUSEEVENT EventTrack1, EventTrack2;
EventTrack1.cbSize = sizeof(TRACKMOUSEEVENT);
EventTrack1.dwFlags = TME_HOVER;
EventTrack1.hwndTrack = m_hWnd;
EventTrack1.dwHoverTime = 10;

_TrackMouseEvent(&EventTrack1);

EventTrack2.cbSize = sizeof(TRACKMOUSEEVENT);
EventTrack2.dwFlags = TME_LEAVE;
EventTrack2.hwndTrack = m_hWnd;
EventTrack2.dwHoverTime = 0;

_TrackMouseEvent(&EventTrack2);
}

void CSkinButton::OnMouseMove(UINT nFlags, CPoint point)
{
CheckHover();

CButton::OnMouseMove(nFlags, point);
}

Related Posts

답글 남기기

이메일 주소는 공개되지 않습니다.